September 2017
Intermediate to advanced
244 pages
6h 44m
English
This will be served from the show($id) method. In our show method, we are just getting the record and returning, but what if ID coming in the show() method that is passed in URLs is incorrect, or records indicate that ID doesn't exist? So, we just need to place a check to make sure that it returns a 404 error, if a post is not found with that ID. Our code for the show() method will look like this:
public function show($id){ $post = $this->post->find($id); if(!$post) { abort(404); } return $post;}
The abort() method will stop execution with an error code passed to it. In this case, it will simply give a 404 Not Found Error.
Read now
Unlock full access