orchidsoftware / platform

Orchid is a @laravel package that allows for rapid application development of back-office applications, admin/user panels, and dashboards.
https://orchid.software
MIT License
4.4k stars 646 forks source link

Search only searching the first model in the config #2609

Closed joshhornby closed 1 year ago

joshhornby commented 1 year ago

Describe the bug When using the global search functionality, only the first model from the search array in the platform.php config is searched against.

    'search' => [
        \App\Models\User::class, // <-- Searching against this
        \App\Models\Order::class, // <-- Is never searched against
    ],

Looking in the SearchScreen file I believe the issue is with the getSearchModel function. This function returns a single model, the first in the collection and then makes a query against only this model.

To Reproduce Steps to reproduce the behavior:

  1. Add 2 models into the search array of the platform config file
  2. When searching, only the first model is queried against.

Expected behavior When using the global search all models listed the search array should be searchable.

tabuna commented 1 year ago

Hi @joshhornby

I appreciate you taking the time to report the issue with the global search functionality. I cannot reproduce the problem you mentioned. Likewise, I added two different models to the configuration and configured them.

'search' => [
    \App\Models\User::class,
    \App\Models\Task::class,
],

Then in the browser I tried to do a search with the database driver and got results from both models:

scrnli_19-05-2023_02-39-15.webm

Do you have any idea what I did wrong to reproduce the error?

joshhornby commented 1 year ago

Thanks for such a quick response @tabuna - also just want to say Orchid is an amazing piece of software.

Let me go back to the drawing board and see what I'm doing wrong - I'll update this ticket shortly.

joshhornby commented 1 year ago

After running a php artisan optimize:clear everything started working, which is odd as I never ran php artisan optimize. Anyway, all working.