@samara
To pass a value in the URL in Laravel, you can use route parameters. Here's how you can do it:
- Define a route with a parameter in your routes file (web.php):
1
|
Route::get('/user/{id}', 'UserController@show');
|
- Define a corresponding controller method that accepts the parameter:
1
2
3
4
5
6
7
|
public function show($id)
{
// Retrieve user information based on the ID
$user = User::find($id);
return view('user.show', ['user' => $user]);
}
|
- Generate the URL with the parameter in your view or controller like this:
1
|
$url = route('user.show', ['id' => $user->id]);
|
- You can access the parameter value in your controller method using the $request object:
1
2
3
4
5
6
7
8
|
public function show(Request $request)
{
$id = $request->route('id');
// Retrieve user information based on the ID
$user = User::find($id);
return view('user.show', ['user' => $user]);
}
|
By following these steps, you can pass values in the URL in Laravel using route parameters.