Laravel 5 getting ID from URL

In Laravel 5, you can get the ID from the URL by using the $request object or by defining a route parameter in the web.php file.

Example using the $request object:

public function show(Request $request, $id) {
    $product = Product::find($id);
    return view('product.show', compact('product'));
}

Watch a course Learn object oriented PHP

Example using route parameter:

Route::get('product/{id}', 'ProductController@show');

public function show($id) {
    $product = Product::find($id);
    return view('product.show', compact('product'));
}

In this example, the {id} parameter in the route is passed as an argument to the show method in the ProductController.