How to search for ListX in global search?
Currently global search can search for a specific record, but I also want it to also search the List pages as I have too many resources types, May I know how to achieve that?
So that things like ListUsers will appear in global search, I see it in pxlrbt/filament-spotlight but I would prefer not to use a package. Especially when spotlight v1 is no longer maintained
Thanks!
30 Replies
I don't think that's possible.
I see it in ur package in which u claim it uses filament global search behind the scenes
this plugin relies on the same properties and methods used for Filament's global search
We see a Discounts - List there
It uses the global search data for searching the records. But the root elements List/Edit/Create/View are collected by the package
Ah okay, would u all consider adding support for this to core filament in the future?
As some of us have many Models
Not sure. @Dan Harrin What's your opinion on this?
i happen to have purchased Spotlight v2 some time ago too but not too sure how to integrate that with filament admin
but I would prefer not to use a package. Especially when spotlight v1 is no longer maintainedI thought about building my own v2 as a Paid Plugin. Not sure if it's worth it though
Maybe something can be worked out with @philonl
I already talked to him. v2 wouldn't be that convenient. You need to buy Spotlight v2 separately, integrate that via Composer and then install a package that connects it to Filament
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i already bought (wire element pros) months ago but haven't use it in any projects yet.
I'm not an expert filament user so find it quite intimidating on how do i get started with integrating spotlight v2 with filament admin
If the process didn't change too much, you could use my package as a baseline.
Alternatively would it be easier for me to extend filament core global search to support searching ListX Pages instead?
It seems doable if I write my own GlobalSearchProvider
https://github.com/filamentphp/filament/blob/2.x/packages/admin/src/GlobalSearch/DefaultGlobalSearchProvider.php
But not sure how to get filament to use my GlobalSearchProvider instead of Filament own one
I guess you need to swap it out via the Laravel Container. But I didn't look into this yet
I traced to FilamentManager.php and saw this line
https://github.com/filamentphp/filament/blob/2.x/packages/admin/src/FilamentManager.php
protected string $globalSearchProvider = DefaultGlobalSearchProvider::class;
Then I search for usage of FilamentManager.php and saw this in FilamentServiceProvider
I see that it is a Scoped Singleton but i'm not sure how do I swap it with My Filament Manager which reference my own GlobalSearchProvider
https://laravel.com/docs/10.x/container#binding-scoped
Do i just do this in my own AppServiceProvider register() method?
Would this be enough to override and have my app use my FilamentManager which reference my GlobalSearchServiceProvider instead of Filament own 1?
ah okay there is this globalSearchProvider(string $provider) method maybe i try call that in the boot method
Will let u all know again if it work for me, but if global search ListX Pages can be supported in filament admin core itself it would be great!
I guess you can return custom global search results from the resource
and link one to the list page of a resource
Currently I did it this way (not working yet). Didn't see ur message before this attempt
MyOwnFilamentServiceProvider
And my AdminGlobalSearchProvider
cool
But it doesn't work 😭
i dont think the boot() bit is right
Hmm so i should do app(FilamentManager::class) ? since FilamentManager is a scoped singleton
Having FilamentManager at boot() didn't throw any error, other than the search still did not show the pages
i think you can just call
Filament::globalSearchProvider(AdminGlobalSearchProvider::class);
as a facadehmm ok let me try
also is the service provider registered
yup service provider is registered.
Ok using Filament::globalSearchProvider(AdminGlobalSearchProvider::class); works
But the pages returned in the search results are the dashboard pages, not the Resource pages like ListUsers
right but you still need to loop through resources
as we do in the default provider
resource pages arent registered in the same way
you just call
ResourceName::getUrl()
to generate the URLThanks it sort of worked! here is my code, feel free to improve & add to core if u want
could be a plugin? :)
but a PR would be good to enable these results optionally
I still prefer to keep my github username private for now so... if anyone wants to make a PR to enable it feel free to take credit for it 🙂
Thanks a lot!