Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between URL::to and URL::route in laravel

What is the difference between

<a href=" {{ URL::route('/account/register') }}" >Register 1 </a>

and

<a href=" {{ URL::to('/account/register') }}" >Register 2 </a>

I defined the routes.php as

Route::get('/account/register','RegisterController@create');

When I click on 'Register 1' I got the following error

Route [/account/register] not defined.

But when I click on 'Register 2' ,it goes to the

RegisterController@create 
like image 377
Kiran Subedi Avatar asked Mar 16 '15 21:03

Kiran Subedi


1 Answers

URL::route gets the URL to a named route. So in your case, if you name your route like this:

Route::get('/account/register', [
    'name' => 'register', 
    'uses' => 'RegisterController@create'
]);

then you will be able to use

<a href="{{ URL::route('register') }}" >Register 1</a>

in blade templates.

like image 133
Limon Monte Avatar answered Oct 07 '22 16:10

Limon Monte