2014-10-21 18:57

Laravel 4自定义身份验证提供程序 - 找不到类错误

  • php
  • authentication

I am trying to implement a custom auth provider by following this guide:

In my project, I have created the following file:


with the sample code from Step #1 and renamed "MyApp" to "Latheesan".

I then went to add the following line in my app/start/global.php

Auth::extend('dummy', function($app) {
    return new Latheesan\Extensions\DummyAuthProvider;

Then updated the app/auth/config.php and changed the driver like so:

'driver' => 'dummy',

Finally I amended my routes.php like this:

Route::filter('auth', function($route, $request) {
    if (Auth::guest())
        return Redirect::guest('login');

Route::get('login',  array('uses' => 'HomeController@showLogin'));
Route::post('login', array('uses' => 'HomeController@doLogin'));
Route::get('logout', array('uses' => 'HomeController@doLogout'));

Route::get('/', function() {
    return View::make('hello');

Before I tested my code, I ran the composer dump-auto to generate autoload files.

When I visited my test site: http://laravel-test.local I am getting this error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR) Class 'Latheesan\Extensions\DummyAuthProvider' not found

Any idea why my custom auth provider class isn't loading?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongqian9013 dongqian9013 7年前

    By default composer doesn't know how to autoload your new class, so you would need to add an PSR rule in the autoload section of your composer.json file. This should do the trick:

    "autoload": {
        "psr-0": {
            "Latheesan": "app/"
    点赞 评论 复制链接分享