jeudi 2 août 2018

Laravel eloquent with Trashed on relationship

I need to be able to get a Models Relationship including its soft deleted elements, but only for this 1 instance. I do not want to change the model so that every time I use the relationship it returns all the soft deleted records too.

How can I achieve this?

User Model

class User extends Authenticatable
{
  public function contacts(){
    return $this->hasMany('App\Contacts','user_id','id');
  }
}

Controller

$user = User::findOrFail($id);
//Need to be able to get the trashed contacts too, but only for this instance and in this function
$user->contacts->withTrashed(); //Something like this
return $user;

How can I get the trashed rows only this 1 time inside my controller?

Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2vtkKG3
via IFTTT

Aucun commentaire:

Enregistrer un commentaire