[英]Laravel 5.4 Redirect back to intended url
Im trying to setup the ability to redirect the user to the original intended url. 我正在尝试设置将用户重定向到原始预期网址的功能。
If a user visits a url and is required to login, it should redirect them to the original url they visited. 如果用户访问一个URL并要求登录,则应将其重定向到他们访问的原始URL。 Ive been doing some reading on Stackoverflow and have come to these solutions, however I cant get it to function as intended (no intended pun :) )
我一直在阅读一些关于Stackoverflow的文章,并且已经找到了这些解决方案,但是我无法使它按预期的功能运行(没有双关语:))
Any ideas on what I am doing wrong? 关于我在做什么错的任何想法吗?
I am on Laravel 5.4.36 我在Laravel 5.4.36上
My LoginController.php
我的
LoginController.php
if (Auth::attempt($credentials, $remember_me, $user->status == 'Confirmed')) {
if ($control_panel->auth_throttle == "on") {
$this->clearLoginAttempts($request);
}
// Added if statement if user is super admin we'll direct to their
// dashboard
if ($user->superadmin == true) {
return redirect()->intended("/admin");
}
// if user is not superadmin we'll direct them to their
// dashboard
else {
return redirect()->intended("v1");
}
}
My RedirectIfAuthenticated.php
我的
RedirectIfAuthenticated.php
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect()->intended();
//return redirect('/admin');
}
return $next($request);
}
From my understanding of reading your question, you want to redirect a user BACK to the previous route after authentication? 根据我对阅读问题的理解,您想在身份验证后将用户BACK重定向到上一条路由吗?
Laravel has a back helper. Laravel有一个后帮手。
https://laravel.com/docs/5.4/redirects#creating-redirects https://laravel.com/docs/5.4/redirects#creating-redirects
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.