I simply suggest you use firstOrFail() instead of findOrFail().
$order = Order::where('order_id', $order_id)->firstOrFail();
Hope it will work fine.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi to all, in my controller i have a find or fail with the input value:
$order = Order::findOrFail($order_id)
If $order_id do not exists, the function throw an exception, and is ok.
But, if i pass the following value (with an existing order):
in both case, the order is found (and the order is 1234)
If i pass a totally inexistent order (for example 345432, that do not exist), this this case the exception is raised
Please or to participate in this conversation.