I have a query that I am doing, what I need is to show only the records that do not match the where clause.
mechanic_client
| id | user_id | mechanic_id |
|---|---|---|
| 13 | 31 | 13 |
| 16 | 34 | 1 |
| 26 | 61 | 1 |
users
| id | name |
|---|---|
| 1 | lucas |
| 31 | mauricio |
| 34 | pedro |
| 61 | carlos |
The user admin lucas created Pedro and Carlos, they are created both in the users table and in the mechanic_client table, so what I want is not to show Pedro and Carlos, only show the other users, but the function does not work for me it continues to show me to all users.
function index
$users_mechanics = DB::table('mechanic_client')->get();
foreach ($users_mechanics as $user_mechanic) {
$users = User::orderBy('id', 'DESC')->with('roles')->where('id', '<>', $user_mechanic->user_id)->paginate(10);
return [
'pagination' => [
'total' => $users->total(),
'current_page' => $users->currentPage(),
'per_page' => $users->perPage(),
'last_page' => $users->lastPage(),
'from' => $users->firstItem(),
'to' => $users->lastItem(),
],
'users' => $users
];
}
query return
| id | name |
|---|---|
| 1 | lucas |
| 31 | mauricio |
it should look like this
Thanks for the help..