how to use where relationship laravel code example

Example 1: laravel where on relation

Event::whereHas('participants', function ($query) {
    $query->where('IDUser', '=', 1);
})->get();

Example 2: how to use where relationship laravel

Event::with(["owner", "participants" => function($q) use($someId){
    $q->where('participants.IdUser', '=', 1);
    //$q->where('some other field', $someId);
}])

Example 3: laravel eloquent associate

$account = App\Account::find(10);

$user->account()->associate($account);

$user->save();

Tags:

Misc Example