Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel route in bootstrap button

I want to make a button that links to route: normindex

This blow does not seem to work.

 <button href={{ HTML::link('normindex')}} type="button" class="btn btn-default">Left</button>
 <button href="normindex" type="button" class="btn btn-default">Left</button>

This below does work but generates a link, not a button.

{{ HTML::link('normindex','Left')}}

Does anyone have any idea?

like image 510
JeffreyR Avatar asked Dec 22 '13 11:12

JeffreyR


Video Answer


2 Answers

Try the following:

<a href="{{ URL::route('normindex') }}" class="btn btn-default"> Norm Index </a>

or

link_to_route('normindex', 'Norm Index', null, array('class' => 'btn btn-default'));
like image 132
Anam Avatar answered Sep 21 '22 17:09

Anam


Well, they don't work because HTML::link() will output a full HTML link, while your second attempt just uses plain text in the href attribute, so there is no way for Laravel to know that it needs to include something in there.


You can try this:

 <button href="{{ route('normindex') }}" type="button" class="btn btn-default">Left</button>

The route() helper will print the URL of the route that you pass to it. This will need a named route in your routes.php file, such as:

Route::get('your-path', array('as' => 'normindex', function()
{
   // do stuff
}));
like image 28
Manuel Pedrera Avatar answered Sep 19 '22 17:09

Manuel Pedrera