Laravel - routing to a folder inside "views"
I am still new to laravel and am learning my way. Usually, for example, if I want to access the "login.blade.php" file (located in the "views" folder), the route will usually be:
Route::get('/login', array('as' => 'login', 'uses' => 'AuthController@getLogin'));
So it works great. But what if I want to have folders inside the "views" folder? For example, I want to direct the file "login.php".
- views
-- account
--- login.blade.php
I tried using:
Route::get('/account/login', array('as' => 'login', 'uses' => 'AuthController@getLogin'));
But I am getting the error "Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException"
What am I doing wrong?
Thank.
source to share
Your understanding of routes and views is incorrect.
The first parameter Route::get
is the URI of the route to be used in your url as domainname.com/routeURI
, and the second parameter can be array()
either closure function
or a string like 'fooController@barAction'
. And Route::get()
has nothing to do with rendering views. Routes and views are not as closely related as you might think.
This can be done with closures as shown below
Route::get('login', array('as' => 'login', function()
{
return View::make('account.login');
}));
Or with a 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
source to share