what is the jobData relation name in your job Model ?
Nov 12, 2019
7
Level 5
eloquent query relations
I have a Job table that hasMany JobData i want to query Job::where('is_active', true)->JobData('title', 'LIKE', $query) (this is just pseudo code)
this is the code I wrote, but the problem is that it gets also Job items that don't satisfy the condition
$jobs = Job::where('is_active', 1)
->whereHas(['data' => function($query) use($keyword) {
$query->where('status', 'pending')
->where('title', 'LIKE', "%{$keyword}%");
}])->get();
the only way I could get the right data I want is with query builder but I can't use the relations in the Model
Level 6
@imadev This is from the Laravel docs, no array as param:
// Retrieve posts with at least one comment containing words like foo%...
$posts = App\Post::whereHas('comments', function (Builder $query) {
$query->where('content', 'like', 'foo%');
})->get();
Please or to participate in this conversation.