laravel eloquent where has associated records code example
Example 1: laravel detach
// Detach a single role from the user...
$user->roles()->detach($roleId);
// Detach all roles from the user...
$user->roles()->detach();
Example 2: laravel how to query belongsTo relationship
$movies = Movie::whereHas('director', function($q) {
$q->where('name', 'great');
})->get();