GRowing
GRowing

Reputation: 4717

Laravel 4.2 - Route keeps failing

I have an app where,, when my user is logged out or a log-in session expires, for some reason a redirect to a sign in page keeps failing.. I keep searching but I am blind to a solution. Can someone look at this and spot me a problem?

I have a user sign in route:

    /*
    | Sign in (GET)
    */
    Route::get('/account/sign-in', array(
        'as' => 'account-sign-in',
        'uses' => 'AccountController@getSignIn'
    ));

The getSignIn simply assembles a view:

public function getSignIn() {
    return View::make('account.signin');
}

I also have the authenticated group routes

/*
| Authenticated group
*/
Route::group(array('before' => 'auth'), function() {

    Route::group(array('prefix' => 'admin'), function()
    {
        Route::get('/languages', array(
            'as' => 'language-list',
            'uses' => 'LanguageController@getLanguages'
        ));
    });
}

And getLanguages is simply like this:

public function getLanguages() {

    if( Auth::check()) {

        $languages = Language::all();

        return  View::make('admin.language')->with('languages', $languages);

    } else {

        return Redirect::route('account-sign-in');
    }
}

It looks like every time this line gets executed the redirect fails

return Redirect::route('account-sign-in');

I get this error:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException



11. Symfony\Component\HttpKernel\Exception\NotFoundHttpException
…\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php148 

Upvotes: 0

Views: 138

Answers (1)

Mysteryos
Mysteryos

Reputation: 5791

This:

public function getSignIn() {
    return View::make('account.signin');
}

Should be that:

public function getSign_in() {
    return View::make('account.signin');
}

Explanation:

From Illuminate API: ControllerInspector.php

/**
 * Determine the URI from the given method name.
 *
 * @param  string  $name
 * @param  string  $prefix
 * @return string
 */
public function getPlainUri($name, $prefix)
{
    return $prefix.'/'.implode('-', array_slice(explode('_', snake_case($name)), 1));
}

Given that laravel uses snake_case to find controller methods, AccountController@getSignIn method name in the Route uses parameter will be converted to snake case, which is getSign_in().

Upvotes: 1

Related Questions