vendredi 4 septembre 2020

Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() laravel 5.8

I create a project whit tow type of user one for admin one for the student using this link

Everything it's ok but when I want to make a request to my postLoging() method the just redirect to my getLogin() method(page refreshed) and I think it because of the auth protection

my web.php file:

Route::group(['prefix' => 'admin'], function (){
    Route::group(['middleware' => 'guest:admin'], function (){
        Route::get('/login', [
            'uses' => 'AdminController@getLogin',
            'as' => 'admin.login'
        ]);

        Route::post('/login', [
            'uses' => 'AdminController@postLogin',
            'as' => 'admin.login'
        ]);
    });

    Route::group(['middleware' => 'auth:admin'], function (){
        Route::get('/', [
            'uses' => 'AdminController@getIndex',
            'as' => 'admin.index'
        ]);
    });
});

and my AdminController file:

class AdminController extends Controller
{
    public function __construct(){
        $this->middleware('auth:admin')->except('getLogin');
    }

    public function getLogout(){
        Auth::logout();

        return redirect()->route('admin.login');
    }

    public function getLogin(){
        return view('admin.login');
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function postLogin(Request $request){
        return $request;
        $this->validate($request, [
            'email' => 'required',
            'password' => 'required',
        ]);

        if(Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')])){
            return redirect()->route('admin.index');
        }

        return redirect()->back()->with('merror', 'ایمیل یا پسورد وارد شده اشتباه است.');
    }

    public function getIndex(){
        return view('admin.index');
    }
}

in construct function, I tried:

when I set tow middleware like this

$this->middleware('auth:admin')->except('getLogin'); $this->middleware('auth:admin')->except('postLogin');

the app will break and the login page doesn't load.

when I try $args = array('getLogin', 'postLogin'); $this->middleware('auth:admin')->except($args ); and $this->middleware('auth:admin')->except('getLogin', 'postLogin'); I get this error

Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must implement interface Illuminate\Contracts\Auth\UserProvider, null given, called in C:\xampp\htdocs\admin\vendor\laravel\framework\src\Illuminate\Auth\AuthManager.php on line 125



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire