Ask Your Question
2

What is the method for sending a variable to a Blade route?

asked 2021-12-11 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-06-07 08:00:00 +0000

woof gravatar image

In Laravel, you can send a variable to a Blade route by using the route function with a second parameter as an array of data. For example:

Route::get('/profile/{id}', function($id) {
   return view('profile', ['user_id' => $id]);
});

In this example, we are passing a variable 'userid' to the profile view with the value of the ID parameter from the route. In the Blade template, you can access the value of the 'userid' variable using the {{ }} syntax:

<h1>User Profile</h1>
<p>User ID: {{ $user_id }}</p>
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-12-11 11:00:00 +0000

Seen: 7 times

Last updated: Jun 07 '21