Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: has() and whereHas() do not support MorphTo relationships. #12

Closed
4n70w4 opened this issue May 6, 2019 · 5 comments
Closed

Comments

@4n70w4
Copy link

4n70w4 commented May 6, 2019

It will be very useful to have support for searching for polymorphic relations.

    public static $searchRelations = [
        'detailable' => ['title', 'inn'],
    ];
    public function detailable() {
        return $this->morphTo('detailable');
    }
    "message": "has() and whereHas() do not support MorphTo relationships.",
    "exception": "RuntimeException",
    "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php",
    "line": 35,
    "trace": [
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php",
            "line": 158,
            "function": "has",
            "class": "Illuminate\\Database\\Eloquent\\Builder",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/titasgailius/search-relations/src/SearchesRelations.php",
            "line": 73,
            "function": "orWhereHas",
            "class": "Illuminate\\Database\\Eloquent\\Builder",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/titasgailius/search-relations/src/SearchesRelations.php",
            "line": 57,
            "function": "applyRelationSearch",
            "class": "App\\Nova\\Organization",
            "type": "::"
        },
        {
@TitasGailius
Copy link
Owner

This is a limitation of the Laravel framework, not this package.

@TitasGailius
Copy link
Owner

#5

@4n70w4
Copy link
Author

4n70w4 commented May 20, 2019

@TitasGailius okay, https://medium.com/laravel-nova/nova-morph-to-search-relations-2296dbb66906 - helps for me.

But it would be nice to add an exception handler to your plugin, and show a more useful message, for example, to a workaround page. It will be convenient for users.

@ghost
Copy link

ghost commented Aug 5, 2019

@TitasGailius just an FYI: laravel/framework#28928 is included in Laravel 5.8.

@jkudish
Copy link

jkudish commented Aug 9, 2019

@TitasGailius can you add support for whereHasMorph now that it is supported, please :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants