-
Notifications
You must be signed in to change notification settings - Fork 291
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
Search polymorphic relation (tags) #222
Comments
@Shi974 hey!
|
Hey @GORAZIZYAN98 ! Thanks for your answer !
If anyone has a little idea, I would be grateful 😄 |
I did it like this:protected $searchable = [
/**
* Columns and their priority in search results.
* Columns with higher values are more important.
* Columns with equal values have equal importance.
*
* @var array
*/
'columns' => [
'dispositifs.di_sigle' => 10,
// ...
'tags.name' => 10,
'tags.slug' => 10,
'tags.type' => 8,
],
'joins' => [
'taggables' => ['dispositifs.id', 'taggable.taggable_id'], // Join the pivot
'tags' => ['taggables.tag_id', 'tags.id'], // Get tags based on joined pivot, now you can use this in "columns"!
]
]; To explain what I did: Downsights: I hope this will be useful to someone! 😄 |
protected $searchable = [
/**
* Columns and their priority in search results.
* Columns with higher values are more important.
* Columns with equal values have equal importance.
*
* @var array
*/
'columns' => [
'dispositifs.di_sigle' => 10,
// ...
'tags.name' => 10,
'tags.slug' => 10,
'tags.type' => 8,
],
'joins' => [
'taggables' => ['dispositifs.id', 'taggables.taggable_id'], // Join the pivot
'tags' => ['tags.id', 'taggables.taggable_id', 'taggables.taggable_type', Taggable::class] // Join taggable_id and _type
]
]; I used a lot of polymorphic relations in my projects, and came accross the same problem. If you dont integrate the If you use |
Hello ! Is there any way to search polymorphic relationship ?
For instance, I am using spatie/laravel-tags package and this adds a polymorphic relationship between my models and the tags table.
So I have those tables and my models : dispositifs, infrastructures, etc. which are tagged and which can be searched.
Taggables
Tags
[...]
How could I search for tags please?
So far, I have this, but it does not seem to work. When I search for a "tag", the results returned are all the models and no point ordering is done ...
Thank you in advance and thanks to @nicolaslopezj for this awesome package ! 😁 👍
The text was updated successfully, but these errors were encountered: