Can Laravel Auth::attempt() handle relationships? -
i'm using entrust managing role based permissions in laravel 5.3, , naturally using manual/custom logins different user types. possible auth::attempt()
handle foreign table relationships? basically, want this:
if(auth::attempt(['email' => $request->email, 'password' => $request->password, hasrole('teacher') => true])) { return redirect()->intended('teacher/dashboard'); }
but keep getting error hasrole()
undefined function. have included use zizaco\entrust\traits\entrustusertrait;
, use entrustusertrait;
, thought provide me access function, apparently not.
i appreciate fact hasrole()
method user objects, , @ time of checking don't have user object can't role check after attempt has succeeded because user has been logged in, , if role wrong need log them out credentials correct, not role; seems slow , not pragmatic.
how should go handling this? there alternative auth::attempt
can use not log in user, check user exists specified input, , run role check, , use function start authenticated session?
if useful logincontroller here:
<?php namespace app\http\controllers\teacher; use app\http\controllers\controller; use illuminate\support\facades\auth; use illuminate\http\request; use validator; use zizaco\entrust\traits\entrustusertrait; class logincontroller extends controller { use entrustusertrait; public function showloginform() { return view('teacher/login'); } public function authenticate(request $request) { validator::make($request->all(), [ 'email' => 'required|email', 'password' => 'required', ])->validate(); if(auth::attempt(['email' => $request->email, 'password' => $request->password, hasrole('teacher') => true])) { return redirect()->intended('teacher/dashboard'); } return redirect('admin/login')->with('invalid', 'invalid username or password'); } }
any or direction appreciated. thanks.
what can is:
if(auth::attempt(['email' => $request->email, 'password' => $request->password)) { if($user = auth::user()->hasrole('teacher')) { return redirect()->intended('teacher/dashboard'); } else { return redirect()->intended('teacher/dashboard'); } }
Comments
Post a Comment