A
A
art_guzev2019-09-12 22:59:50
Laravel
art_guzev, 2019-09-12 22:59:50

How to properly implement destroy in Laravel?

Destroy does not work on the order editing page, it gives an error 500. Although when I delete a dish in the same order on the same page, everything is ok.
Delete button on the page

<button class="btn btn-danger float-sm-right js_order_destroy_btn" data-href="{{ route('cms_panel.orders.destroy',['order_id'=>$orders_row->id]) }}" type="button" style="margin: 0 10px;">Удалить</button>

Below in js I confirm the deletion
$('.js_order_destroy_btn').click(function() {
    if(confirm('Вы уверены, что хотите удалить заказ?')) location.href=$(this).data('href');
});

And the controller itself:
public function destroy(Request $request, $id)
{
    $row = Orders::withTrashed()->findOrFail($id);

    Orders::destroy($id);

    return redirect()->route('cms_panel.orders.index', [])
        ->with('success','Deleted successfully');
}

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