Ethan McKee Ethan McKee - 4 years ago 106
PHP Question

Laravel - routing to a folder inside "views"

I'm still new to laravel and learning my way through.
Normally, for example, if I want to access the file "login.blade.php" (located in "views" folder), the route would normally be:

Route::get('/login', array('as' => 'login', 'uses' => 'AuthController@getLogin'));


So the above works just fine. But what if I want to have folders inside the "views" folder? For example, I want to route the file "login.php".

- views
-- account
--- login.blade.php


I tried using:

Route::get('/account/login', array('as' => 'login', 'uses' => 'AuthController@getLogin'));


But I get an error saying "Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException"

What am I doing wrong?

Thank you.

Answer Source

Your understanding on routes and views is not correct.

The first parameter of Route::get is the route URI which will be used in your url as domainname.com/routeURI and second parameter can be an array() or closure function or a string like 'fooController@barAction'. And Route::get() has nothing to do with rendering views. Routes and Views are not that closely coupled as you think.

This can be done by closures like below

Route::get('login', array('as' => 'login', function()
{
    return View::make('account.login');
}));

Or with controller action

Route file:

Route::get('login', array('as' => 'login', 'uses' => 'AuthController@getLogin'));

AuthController file:

public function getLogin()
{
    return View::make('account.login');
}

You can find more at http://laravel.com/docs/4.2/routing or If you prefer video tutorials, go to http://laracasts.com

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download