I wanna use authenticated() in my login() return type. I wanna try to when user try to login via their phn_number they can login and it also check middleware / user_role. This part of code i write on autheticated() . so my plan is when i login , the login() will return via the authenticated() also.
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\SiteSettings;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Auth;
use User;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected function authenticated (Request $request, $user)
{
if (Auth::check() && Auth::user()->role->id == 1 ) {
$this->redirectTo = route('admin.dashboard');
} elseif(Auth::check() && Auth::user()->role->id == 2 ) {
$this->redirectTo = route('doctor.dashboard');
} elseif(Auth::check() && Auth::user()->role->id == 3 ) {
$this->redirectTo = route('nurse.dashboard');
} else {
$this->redirectTo = route('search.doctor');
}
}
// protected $redirectTo = $this->authenticated();
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function field()
{
if (filter_var(request()->phn_number,FILTER_VALIDATE_EMAIL)){
return 'email';
}else{
return 'phn_number';
}
}
public function login()
{
// Check Right Position
// return $this->field();
if (Auth::attempt([$this->field()=>request()->phn_number, 'password'=>request()->password ])){
// Wanna Return Authenticated function
//return redirect()->intended('/');
return redirect()->intended($this->authenticated());
}else{
return redirect()->back()->withInput('phn_number');
}
}
}
So It's returned me Too few arguments to function App\Http\Controllers\Auth\LoginController::authenticated().
I also try to use
return $this->authenticated();
It also give me error.
$this->authenticated(request(), Auth:user()), but you don't really needs that information in that function, just remove themprotected function authenticated () { //... }