In Laravel, when I want to get data from a table that contains some relationship, or when I want to get the data from a condition in a related table, for example, usuarios
containing livros
, I use the methods has
or whereHas
.
So:
Usuario::has('livros')->get();
Or so:
Usuario::whereHas('livros', function ($query)
{
$query->where('titulo', '=', 'Harry Potter');
})->get();
But now I need the reverse situation.
I want to capture only users who do not have relationships with Livros
.
I want to capture only users who do not have relationships with Harry Potter
books.
How can I do this in Laravel?