I am creating an interactive text form input using Livewire.
When the user types some characters into the text box I wish to return the filtered registrations from a table that has a hasMany relationship to the user.
In essence, the user hasMany cars. (although the key is creator_id, not user_id).
I am trying to do something along the lines of:
public function getSuggestions()
{
$user = Auth::user();
return $user->registrations->where('registration','like', '%' . $this->search . '%');
}
The user model contains the relationship:
public function registrations():HasMany
{
return $this->hasMany(Registration::class,'creator_id');
}
When I just use the following without trying to filter the query...
return $user->registrations;
I get a collection of all registrations owned by the user, which is correct. it also calls the function to return the registrations each time I type a character, so Livewire is working correctly
However, I cannot work out how to alter the query, so the returned registrations are filtered on the like clause.