Я пытался перенаправить пользователя после входа в систему, пользователи должны быть перенаправлены при выполнении определенного условия.
В LoginController предоставлен Laravel
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');
}
}
В RedirectifAuthenticated.php от laravel.
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)
Задача ещё не решена.
Других решений пока нет …