public function show(Item $item)
{
return view('items.show', compact('item'));
}
What is the Laravel convention for checking if a record exists on this method (i.e. handling No query results for model [App\Item])? A try, catch block in the controller method?
New to Laravel. Asking about the basic standard here. Thanks in advanced!
What you're doing is fine, would you like to display a 404 page of some sort if no model is found?
For Laravel 5.1, open up your Handler.php file in app/Exceptions and implement this into your render() method.
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
This now throws a NotFoundHttpException for all ModelNotFoundException's. Meaning you can simply create a 404.blade.php file in resources/views/errors and Laravel will know to use that view to display a 404 page.
But, if you're using 5.2 then you can go ahead and skip the part where you amend your Handler.php file and just create the 404.blade.php file.
Actually, what I was hoping to do was to display my own custom view completely, and for this specific method. What is the Laravel standard way of catching this in a controller method?