Miguel Stevens
Miguel Stevens

Reputation: 9201

Laravel Controller Routes

I'm using a controlled route as such

Route::controller('company', 'CompanyController');

In this Controller i have a getLogin and postLogin function, the getLogin shows the login view. To get there i need to go to company/login

Now i'm wondering how can i redirect company/ to company/login

I have the following working but is it good practice?

Route::get('company', 'CompanyController@getLogin');
Route::controller('company', 'CompanyController');

Thank you!

Upvotes: 1

Views: 94

Answers (1)

user1669496
user1669496

Reputation: 33058

In this case, index methods will respond to the root URI, so what you can do is create a getIndex() function which will return Redirect::to('company/login'). You can probably do a check on this for a logged in user first as well, for example...

public function getIndex()
{
    if(!Auth::check())
        return Redirect::to('company/login');

    // Continue with what should happen if the user is logged in.
}

This way, when someone goes to /company, it will redirect them to login if they aren't logged in already or it will continue doing whatever you want it to do or redirect them to the same page you are redirecting people to after they login.

This also means you can do away with that Route::get() that you have setup for company.

Upvotes: 1

Related Questions