Laravel — P41: Controller Show Method (CMP)
The last article ended with us showing all of the resources in the personal_cars
table. We need to be able to click on the resource and pull up the details for it. This is what the show
method will do. It accepts a resource $id
and then pulls the information from it.
Adding the Link to Our Index View
Before we can start working on the show
method, we need to have a way to get to it. The route exists, so that’s one thing already cross off the list.
Route::prefix('/personalcars')->group(function() {
// ...
Route::get('/{id}', [PersonalCarController::class, 'show']);
});
The user simply needs to type in localhost/personalcars/1
to get the first resource. Let’s add the links to our resources/views/personalcars/index
file. I’ll add one more column at the end to create our link.
<x-layouts.app title="{{ $title }}">
<div class="flex bg-white mt-12" style="height:600px;">
<div class="items-center text-center lg:text-left px-8 md:px-12 lg:w-full">
<div…