Reputation: 1362
I start a new laravel project make composed by two pages, I created the pages under the app/view
directory and this is my route.php
file:
Route::get('/', function()
{
return View::make('hello');
});
Route::get('welcome', function()
{
return View::make('welcome');
});
Route::any('signup', function()
{
return View::make('signup');
});
I can access to the pages signup by taping the link directly in the browser and also when I run artisan routes it shows me the routes that I created.
in the welcome.blade.php
when I add the line
{{link_to_route('signup')}}
and reload the page I have this error
ErrorException
Route [signup] not defined. (View: C:\wamp\www\atot\app\views\welcome.blade.php)
how can I solve this problem?
Upvotes: 0
Views: 7126
Reputation: 146269
You should use either:
{{ link_to('signup') }}
Or declare the route using a name
Route::any('signup', array('as' => 'signup', function()
{
// ...
}));
The link_to_route
helper function only works with a named route which accepts a route name in the first argument.
Upvotes: 1
Reputation: 23982
Link_to_route is a method that generates a url to a given named route, so to make it work you can name each of your routes and then it will work
link_to_route('route.name', $title, $parameters = array(), $attributes = array());
In routes.php update the following
Route::get('/', array('as'=>'home', function()
{
return View::make('hello');
}));
Route::get('welcome', array('as'=>'welcome', function()
{
return View::make('welcome');
}));
Route::any('signup', array('as'=>'signup', function()
{
return View::make('signup');
}));
Then you can generate the following routes:
{{link_to_route('home')}}
{{link_to_route('welcome')}}
{{link_to_route('signup')}}
Upvotes: 1
Reputation: 4580
Try this instead:
Route::any('signup', [
'as' => 'signup',
function() {
return View::make('signup');
}
]);
Your problem was that you didn't use a named route.
If you want, you can read more about it here: http://laravel.com/docs/routing#named-routes
Upvotes: 3