E
E
Evgeny Romashkan2018-05-08 15:35:33
Laravel
Evgeny Romashkan, 2018-05-08 15:35:33

How to get all child models, including those deleted with soft delete?

The online store has classes:
Order, Order_product, Product.
Order contains

public function order_products()
    {
        return $this->hasMany(Order_product::class);
    }

Order_product contains
public function product()
    {
        return $this->belongsTo(Product::class);
    }

Information about the goods in the order is displayed in the following way:
$order_product->product->*свойство товара*
The fact is that the goods can be deleted (with soft delete), but still remain in the orders. How then to receive an order with
its order_products, so that each order_product contains a product even if it is deleted?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-05-08
@EvgeniiR

Constraining Eager Loads

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question