11

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 
Kiran Subedi
  • 2,244
  • 3
  • 17
  • 34

3 Answers3

12

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.

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
9

Url::route is used only if you have named routes. So if I called my route "my route" then I could call it like so: URL::route('my route');

But if you want to direct to a route that only has a destination and is not named, then you should use URL::to

Severian
  • 427
  • 3
  • 18
0

First Create Named Routes

Route::get('register',function(){
  return "register page";
})->name('register');

then you will be able to use

 $url = route('register');

<a href="{{url($url)}}">Register</a>