Question

I am putting my Controller called "LoginController" in a folder "login".

class LoginController extends BaseController{
    public $restful = true;
    //log in function
    public function Login(){

        // load the login page
        return View::make('login.login');

    }
}

In the routes, I give this:

Route::get('/',array('uses'=>'login.LoginController@Login'));

Also tried

Route::get('/',array('uses'=>'login\LoginController@Login')); 

Route::get('/',array('uses'=>'login\Login@login')); 

None of the above seem to work, and give me Class does not exist error. I am very dumbstruck with this error. Is the way I am accessing the controller in the "uses" correct? Do I need to do any additional things before I can get it to work?

Any help really appreciated!

Était-ce utile?

La solution

All you should need is

Route::get('/',array('uses'=>'LoginController@Login'));

Composer need to register this change in routes so dump-autoload composer

php composer.phar dump-autoload

Also if you are using laravel 4, then declaring restful controllers with

public $restful = true; 

no longer works.

Autres conseils

this happens to me often, just to give a different answer that worked for me

php artisan dump-autoload

Enjoy!

Yeah i had the same issue, i got my answer from https://stackoverflow.com/a/31638718/2821049

Route::group(['namespace' => 'login'], function(
{
    // Controllers Within The "App\Http\Controllers\login" Namespace
    Route::get('/','LoginController@login');
});

In class you adds :

namespace App\Http\Controllers\folder;
use App\User;
use App\Http\Controllers\Controller;

and in routes you call:

Route::get("admin/login","folder\class@NameFunctionInClass");

Note: folder is the name folder class contains

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top