我一直在尝试在登录后重定向用户,当满足某个条件时,用户将被重定向到。
在 Laravel 提供的 LoginController 中
line 31->protected function redirectTo(Request $request){
if($request->session()->has('credentials')){
$branch_id = $request->session()->get('credentials')[1];
return view('/home'.$branch_id);
}
else{
return view('/auth.login');
}
}
在 laravel 的 RedirectifAuthenticated.php 中。
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
$setBranch = User::on('default')->where('email', $request->email)->first();
$request->session()->put(['branch_id' => $setBranch->branch_id]);
return redirect('/home');
}
return $next($request);
}
在我的 AssetController.php 文件中
public function count_assets(Request $request, $branch = null) {
//set branch id in session for super admin by getting branch in the url that was selected
$setBranch = Branch::on('default')->where('branch_db', $branch)->first();
if($setBranch != null){
session(['branch_id' => $setBranch->branch_id]);
}
$count_assets = Asset::get()->count();
$count_items = Item::get()->count();
$count_department = Department::get()->count();
$count_support = User_support::get()->count();
$count_items_trans = Item_assignment::get()->count();
$count_assignment = Assignment::get()->count();
$count_staff = Staff::get()->count();
return view('home', [ 'count_assets' => $count_assets,'count_items' => $count_items, 'count_department' => $count_department, 'count_support' => $count_support,
'count_items_trans' => $count_items_trans, 'count_assignment' => $count_assignment, 'count_staff' => $count_staff]);
}
现在在 web.php 文件中我有这样的路线
Route::get('/home/{branch?}', 'AssetController@count_assets');
当我尝试登录时,它说
ErrorException Argument 1 passed to App\Http\Controllers\Auth\LoginController::redirectTo() must be an instance of Illuminate\Http\Request, none given, called in C:\xampp\htdocs\laravel\mis_app\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RedirectsUsers.php on line 15 and defined
LoginController.php (line 31)