Basically I have installed Laravel Scout with TNT Search, all of the configs are correct and they work, I even got a nice search bar to work with an ajax workflow
But the results from the models are from the entire database collection where as my requirement is only to show results of record of records created by the user who is currently logged in session
The models are related via Eloquent Relationships, they work when access normally via the Auth::user()
method but the scout search seems to not be attached to any of the models via the Auth::user()
example:
App\CourtCase::search($request->q)->get();
The above works but will return any result in the model (and underlying table) without any regards to if the record is owned or related to the user logged in. My intention is however
Auth::user()->courtcase()->search($request->q)->get();
The error i get is the following
message Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::search()
exception BadMethodCallException
file /home/vagrant/code/legistant/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php
Clearly this is because Laravel Scout is not attached or available via the Auth::user()
method, I can write code to filter the results after they are returned, but imagine the over head of results before being scope by user, it seems like a waste of all that querying, is there a way to scope to user then use Laravel scout search similar to Auth::user()
Can modify the Auth behavior to attach scout, will it be overwritten using a composer update of Laravel?