laravel relationship with where condition code example
Example 1: laravel where condition on relationship
App\Request::where('id',4)
->whereHas('quotes', function ($query) {
$query->where('status','=','3');
})
->with('quotes','sourceTable','destinationTable')
->get();
Example 2: how to use where relationship laravel
Event::with(["owner", "participants" => function($q) use($someId){
$q->where('participants.IdUser', '=', 1);
}])
Example 3: laravel adding condition to relation
class Game extends Eloquent {
public function videos() {
return $this->hasMany('Video');
}
public function available_videos() {
return $this->videos()->where('available','=', 1)->get();
}
}