How to pass id from Html::link to controller

530 views Asked by At

I have a link

 {{ Html::link('/Edit/$user->s_no', 'Edit', array('id' => $user->s_no,'class' =>'btn btn-info'), true)}} 

Route

Route::get('/Edit/{id}',['as'=>'EditUser','uses'=>'RegistrationController@Edit']);

controller

public function Edit($id)
    {
       echo $id;
    }

But when i echo $id it always shows $user->s_no(static) as value.I want to get id as 1,2,3 etc.What is wrong with me?I don't know i am doing right way or not.Please help me?

2

There are 2 answers

8
Anurag_Soni On

Try this :

 {{ Html::link('/Edit/id', 'Edit', array('id' => 1,'class' =>'btn btn-info'), true)}} 

or

 {{ Html::link('/Edit/$user->s_no', 'Edit', array('id' => 1,'class' =>'btn btn-info'), true)}} 

and if you setting id dynamically then you should get that value in variable first and then concatenate it with id like:

 {{ Html::link('/Edit/id', 'Edit', array('id' => "your variable" ,'class' =>'btn btn-info'), true)}} 
0
Anurag_Soni On

Please check this link for more detail link enter link description here

If the controller action method takes arguments, you can specify them in the third parameter, as a simple array.

{{ HTML::linkAction('ItemController@show', 'Show Item #3', array(3)) }}

The HTML would look like below (depending on your routes).

<a href="http://your.url/items/3">Show Item #3</a>

enter image description here