Be careful, you wrap your query twice with "%"
You can check this part of laravel documentation : https://laravel.com/docs/7.x/eloquent-relationships#querying-relationship-existence
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've got this model that query's my volunteer table, I'd like to relate it to my job_positions table
public static function search($query)
{
return empty($query) ? static::query()
: static::where('related_experience', 'like', '%'.$query.'%')
->orWhere('firstname', 'like', '%'.$query.'%')
->orWhere('lastname', 'like', '%'.$query.'%');
}
I can't figure out how to search a query with a join rather than just a single table... something like this
$applicants = \DB::table('volunteerapplicants as v')
->join('joblistings as j', 'v.joblisting_id', '=', 'j.id')
->get();
for reference here is my livewire controller
public function render()
{
return view('livewire.volunteer-applicants', [
'applicants' => \App\VolunteerApplicants::search('%'.$this->search.'%')
->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
->paginate($this->perPage),
]);
}
yes my model / controller return what I expect, but I'd also like the title of my job listing.
I figured it out, just needed to add my join in the livewire controller
return view('livewire.volunteer-applicants', [
'applicants' => \App\VolunteerApplicants::search($this->search)
->join('joblistings', 'volunteerapplicants.joblisting_id', '=', 'joblistings.id')
->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
->paginate($this->perPage),
]);
Please or to participate in this conversation.