ollieread / multiauth

Laravel multi auth
441 stars 109 forks source link

Problem Class auth.driver does not exist #108

Closed eduavila closed 5 years ago

eduavila commented 8 years ago

php artisan route:list

[ReflectionException]
Class auth.driver does not exist

I am having trouble Class auth.driver does not exist. I performed testing and authentication is working but when I run the command 'php artisan route: list' it returns this error.

Laravel 5.0

alizons commented 8 years ago

I have the same error, but in different case - its happening when I am trying to use route 'guest' middleware from default laravel 5.1 installation.

Kernel.php

protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'jwt.auth' => 'Tymon\JWTAuth\Middleware\GetUserFromToken',
        'jwt.refresh' => 'Tymon\JWTAuth\Middleware\RefreshToken',
    ];

Middleware

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Auth\Guard;

class RedirectIfAuthenticated
{
    /**
     * The Guard implementation.
     *
     * @var Guard
     */
    protected $auth;

    /**
     * Create a new filter instance.
     *
     * @param  Guard  $auth
     * @return void
     */
    public function __construct(Guard $auth)
    {
        $this->auth = Auth::admin();
    }

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if ($this->auth->check()) {
            return redirect('/home');
        }

        return $next($request);
    }
}

Sample controller

<?php

namespace App\Http\Controllers\Admin\User;

use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use App\Models\UserPersonalInfo;
use Illuminate\Http\Request;
use App\ProviderUser;
use Validator;

class UserAccountController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    /**
     * Create a new password controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    public function index() {

    }

auth config

<?php

return [

        'multi' => [
            'admin' => [
                'driver' => 'eloquent',
                'table' =>  'users',
                'model' => 'App\User',
            ],
            'client' => [
                'driver' => 'database',
                'table' =>  'users',
                'table' => 'clients',
                'email' => 'App\ConsumerUser',
            ]
        ],
        'password' => [
                'email' => 'emails.password',
                'table' => 'password_resets',
                'expire' => 60,
            ],

    ];

Error I am getting

ReflectionException in Container.php line 737:
Class auth.driver does not exist

Overall plugin seems to be working, but I am having some hard time to make some routes protected from guest users. Any help would be greatly appreciated. Thanks!

ollieread commented 8 years ago

Sounds like you still have default Auth loaded somewhere. It's trying to access auth.driver which using laravels array access function would be where the driver is stored in default laravel configs.

ramaces commented 5 years ago

i have the same problem with

    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.1.3",
        "barryvdh/laravel-dompdf": "^0.8.2",
        "dompdf/dompdf": "^0.8.2",
        "fideloper/proxy": "^4.0",
        "intervention/image": "dev-master",
        "laravel/framework": "5.6.*",
        "laravel/passport": "^7.3",
        "laravel/socialite": "~3.2.0",
        "laravel/tinker": "^1.0",
        "laravelcollective/html": "5.6.*",
        "mollie/laravel-mollie": "^2.0",
        "paypal/rest-api-sdk-php": "*",
        "phpmailer/phpmailer": "^6.0",
        "rachidlaasri/laravel-installer": "1.4.1",
        "smartins/passport-multiauth": "^4.1",
        "spatie/laravel-translatable": "4.0.0"
    },
    "require-dev": {
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0",
        "symfony/css-selector": "2.8.*|3.0.*",
        "symfony/dom-crawler": "2.8.*|3.0.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "files": ["app/Http/helpers.php"]
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "extra": {
        "laravel": {
            "dont-discover": [
                "spatie/laravel-translatable"
            ]
        }
    }
}

did you solved ?

ollieread commented 5 years ago

@ramaces This package does not support 5.6