Searchable MorphTo
I want to make a column searchable:
The model.name is from a relation:
But when I do a search I get an error: TypeError
PHP 8.2.15
11.15.0
Illegal offset type
Please help! Thanks!
Solution:Jump to solution
Having a relation named 'model' seems like it might break something, or at the very least be confusing. I'm not sure on your specific error here, but you can pass a closure to searchable() and override the query to search specific columns of your MorphTo models.
```->searchable( query: fn ( $query, string $search)
=> $query
->orWhereMorphRelation(...
2 Replies
Solution
Having a relation named 'model' seems like it might break something, or at the very least be confusing. I'm not sure on your specific error here, but you can pass a closure to searchable() and override the query to search specific columns of your MorphTo models.
Thanks nanopanda! Your code has solved this issue.