I'm trying to use withTrashed() with eager loading. I've created a new _withtrashed function in my model, but the query comes back with a NULL for my client
Client model:
// Client
public function client()
{
return $this->belongsTo('App\Client');
}
// Client (withtrashed for soft deletes)
public function client_withtrashed()
{
return $this->belongsTo('App\Client')->withTrashed();
}
Order controller
/**
* Show order.
*/
public function show($id)
{
$order = Order::with('client_withtrashed') ---> it works normally with: Order::with('client') , except I don't get the soft deleted rows
->where('id', '=', $id)
->firstOrFail();
dd($order); displays an empty client
#relations: array:1 [
"client_withtrashed" => null
Any ideas? I decided on the solution above because I couldn't get withTrashed() to work with my eager query $order = Order::with('client_withtrashed')->withTrashed()
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire