When writing a query it's common to use closures when using https://laravel.com/docs/9.x/queries#advanced-where-clauses or https://laravel.com/docs/9.x/queries#logical-grouping in-order for the query to behave as expected. $users = DB::table('users') ->where('name', '=', 'John') ->where(function ($query) { $query->where('votes', '>', 100) ->orWhere('title', '=', 'Admin'); }) ->get(); Enter fullscreen mode With more complex queries which have numerous closures the repeated use of the $query argument can make readability awkward. $users = DB::table('users') ->where('name', '=', 'John') ->where(function ($query) { $query->whereHas('role', function ($query) { $query->whereIn('slug', ['leader', 'deputy']) ->whereHas('team', function ($query) { $query->whereIn( 'slug', ['sales', 'finance'], ); }); }); }) ->get(); Enter fullscreen mode
$query->whereIn( 'slug', ['sales', 'finance'], ); // If the query argument has been named, // then we immediately know which table it is 🙂 $teams->whereIn( 'slug', ['sales', 'finance'], ); Enter fullscreen mode