Answers for "select not pivot eloquenr"

0

select not pivot eloquenr

// Simple query

User::doesntHave('Role')->get();

//SELECT * FROM users WHERE ((SELECT count(*) FROM roles WHERE user.role_id = roles.id) < 1)

// For complex query

$id = 1;
User::whereDoesntHave('Role', function ($query) use($id) {
      $query->whereId($id);
})
->get();

//SELECT * FROM users WHERE ((SELECT count(*) FROM roles WHERE user.role_id = roles.id and id = 1) < 1)
Posted by: Guest on September-29-2021

Browse Popular Code Answers by Language