Using Laravel 5, should abort(404) be returned or will it abort and throw an error and stop my method? I have seen both and both seem to work.
public function show($id)
{
try {
$item = Item::where('id',$id)->firstOrFail();
}
catch(ModelNotFoundException $exception)
{
return abort(404);
}
return view('item.show')->with(compact('item'));
}
firstOrFail() will throw an error if a model is not found. If you want to catch it I would suggest doing it in the global.php
Yo do not need to return the abort() as shown in the documentation
You can abort 404 or 403 error.http://laravel.com/docs/5.0/errors#http-exceptions
abort(404, 'Page Not Found');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With