0

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?

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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')}}

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.