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.

3
  • 1
    You're confusing the route with the view file that your controller's action will render. Commented Oct 27, 2014 at 6:55
  • Inside AuthController::getLogin() you would use $this->layout->content = View::make('account/login'); Commented Oct 27, 2014 at 6:56
  • can i see Controllers code ? Commented Oct 27, 2014 at 6:56

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
@EthanMcKee welcome. Almost everything on laravel holds single responsibility. Its such a beauty.
1

you need to write following code in AuthController.php Controller

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.