Try withTrashed first, like:
https://laravel.com/docs/10.x/eloquent#including-soft-deleted-models
$flights = Flight::withTrashed()
->where('account_id', 1)
->get();
Just example from docs.
Hello,
I have the user model with the soft deletetion activated.
The user model is binded to the team model and can belong to many different teams, so it's a belongsToMany relationship via a pivot table.
// team model
public function users()
{
return $this->belongsToMany(User::class);
}
In some cases I need to retrieve only the non deleted team's users.
$team = Team::find(4);
$members = $team->users;
In other cases I need to retrieve all the team's users, those non deleted and the solf deleted ones .
$team = Team::find(4);
$members = $team->users-> ... ?
How is it possible to retrieve the soft deleted users via the relationship ?
I have tried to add ->withTrashed() but it doesn't work.
$members = $team->users->withTrashed(); // doesn't work
If you can help me, it would be great ;).
Thanks for your help.
V
$members = $team->users()->withoutTrashed()->orWhere(function ($query) {
$query->onlyTrashed()->has('quizzes');
})->get();
Please or to participate in this conversation.