M
M
Maria_Gavrilova2019-08-13 18:44:16
Laravel
Maria_Gavrilova, 2019-08-13 18:44:16

Organization of child sections in laravel?

I have a Section entity and an Order entity which belongs to Section. That is, order has a section_id field.
When I navigate to the url: /sections/3/orders/2 the controller's Order show method executes:

public function show(Section $section, Order $order)
{
    return view('orders.show', compact('section', 'order'));
}

But the problem is that this does not take into account that this section with id equal to 3 does not have an order with id equal to 2, but it still gives a response, and I want a 404 to be thrown. Tell me how to do this? What is the standard way to solve the problem? Or I will have to make a request in the method: Order::where('id', $order->id)->where('section_id', $order->section_id). But in the future I will have another nested entity in relation to Order, and in its controller it turns out that I will search for three parameters already ... I thought there was a way to do this in laravel so that it automatically looked at the connections and issued 404 if parent entity does not have such a child and vice versa.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question