https://laravel.com/docs/10.x/controllers#restful-partial-resource-routes
Slugs are important when it comes to seo friendly url. We will see how to use slugs for url instead of ID.
/**
* Display the specified resource.
*/
public function show(String $slug)
{
$post = Post::where('slug', $slug)->first();
if (!$post) {
abort(404);
}
return view('posts.show', compact('post'));
}
Route::get('posts/{slug}', [PostController::class, 'show'])->name('posts.show');
Route::resource('posts', PostController::class)->except([
'show'
]);
- Log in to post comments