Answer the question
In order to leave comments, you need to log in
How to get pretty url in Laravel?
There is such a route and method
Route::get('/{slug}', [App\Http\Controllers\IndexController::class, 'show'])->name('show');
public function show($slug)
{
$ad = Ad::where('slug', $slug)->firstOrFail();
return view('ad', compact('ad'));
}
href="{{ route('show', ['slug' => $ad->slug]) }}"
public function getRouteKeyName()
{
return 'slug';
}
Answer the question
In order to leave comments, you need to log in
You are using getRouteKeyName()
, you then need to change the show method, something like this:
public function show($ad)
{
return view('ad', compact('ad'));
}
Route::get('/{ad}', [App\Http\Controllers\AdController::class, 'show'])->name('show');
In the route, drop this code to the very bottom
Route::get('/{slug}', [App\Http\Controllers\IndexController::class, 'show'])->name('show');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question