I am writing a query using with and then where clause in laravel.
$users = User::query()->with('roles')->where('name', '!=', 'customer')->get(); return $users; But where clause is not working here. Customers are not excluded. I am providing the snap shot of the query result.

where()clause is working here for youruserstable, not for therolestablewhereis only on the User query, not the Roles query. If you want it on the roles query, you'll need to pass it in as a closure. laravel.com/docs/8.x/…