Reputation: 307
Here my ORM that I'm running:
$developers = Developer::where('name', 'LIKE', '%'.$query.'%')->with('programs')->get();
The model for Developer is this:
public function programs()
{
return $this->hasMany('App\Program');
}
This is bringing back all the names from the Developer table not from the programs tables. How would I go about trying to get all the the program names instead of the developer names?
Upvotes: 0
Views: 47
Reputation: 913
Try Like this:
$query = "hello";
$developers = Developer::whereHas('programs', function($q) use($query){
$q->where('name', 'LIKE', '%'.$query.'%');
})->get();
It will help you!
Upvotes: 1