Laravel Route Model Binding

Route model binding in Laravel provides a mechanism to inject a model instance into your routes.

// the route parameter is the id of the post
// for example
Route::get('posts/{id}', function ($id) {

    // we have to find the post using the $id
    $post = Post::find($id);

    // if there is no post, 404
    if (!$post) return abort(404);

    // return the view and the post
    return view('', compact('post'));