As far as I know using firstOrFail() in laravel5.1 without catching the exception results in a 404 error. My controller code:
public function getTicket($id = null)
{
$validator = Validator::make(compact('id'),[
'id' => 'required|regex:/^[1-9]\d*$/',
]);
if ($validator->fails())
dd("no");
$tickets = Auth::user()->tickets()->where('id', $id)->firstOrFail();
dd($tickets);
}
When I use a not existing id of ticket I just get this error:
ModelNotFoundException in Builder.php line 157: No query results for model [App\ticket].
How to trigger a 404 error page? As laravel doc told me
If the exception is not caught, a 404 HTTP response is automatically sent back to the user[...]
this shoud be done in my case.laravel doc
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire