I want to create dynamic route on my navbar and redirect it to http://localhost:8000/tasks/nenad page
Web.php
Route::get('/tasks/{first_name}', 'Viewercontroller@profile')
->middleware('viewer')
->name('profile');
ViewerController
public function profile($first_name) {
$user = User::whereFirst_name($first_name)->first();
return view('viewers/tasks', compact('user'));
}
Navbar.blade.php:
<li><a href="{{ url(route('profile')) }}">Tasks</a></li>
I know that i have to change link on my navbar page but doesn't know how, any help will be great...
it won't work because your route expects a parameter, so you have to indicate on your navbar.blade.php the parameter you want to pass.
For example I'll assume you have a user saved on $user, then you would do this:
route('profile', ['first_name' => $user->name]);
You can read more about URL generation on Laravel docs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.