5

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.

Ethan McKee
  • 215
  • 2
  • 3
  • 7

2 Answers2

4

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

brainless
  • 5,698
  • 16
  • 59
  • 82
  • 1
    You are awesome. Thank you very much! Now I understand, and it's even nicer that I can use Controller functions so this way I can filter. – Ethan McKee Oct 27 '14 at 08:58
  • @EthanMcKee welcome. Almost everything on laravel holds single responsibility. Its such a beauty. – brainless Oct 27 '14 at 09:47
1

you need to write following code in AuthController.php Controller

public function getLogin()
{
      return View::make("account.login");
}
Anand Patel
  • 3,885
  • 3
  • 17
  • 23