php – Laravel 5.4登录后重定向到自定义URL
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Laravel 5.4登录后重定向到自定义URL,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1968字,纯文字阅读大概需要3分钟。
内容图文
![php – Laravel 5.4登录后重定向到自定义URL](/upload/InfoBanner/zyjiaocheng/712/a8a8967b3c6e4aa18d9a0a41faecbbf0.jpg)
我正在使用Laravel Framework 5.4.10,我正在使用常规身份验证
php artisan make:auth
提供.我想保护整个应用程序,并在登录后将用户重定向到/ themes.
我有4个控制器:ForgotPasswordController.php,LoginController.php,RegisterController.php和ResetPasswordController.php.我已将此行编辑为最后三行:
protected $redirectTo = '/themes';
这是我的routes / web.php中的第一行:
Auth::routes();
我在Controller.php中添加了这个函数:
public function __construct()
{
$this->middleware('auth');
}
我编辑了app / Http / Middleware / RedirectIfAuthenticated.php,因此handle函数如下所示:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/themes');
}
return $next($request);
}
一切都很好,除非我点击登录按钮,我被重定向到“/”,而不是“/ themes”.如果我不需要在控制器中进行身份验证(Controller.php文件中没有__contruct函数),我会在登录时重定向.我究竟做错了什么?
解决方法:
这就是我正在努力工作,这是多么巧合.
您还需要在LoginController中添加以下行
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
protected function authenticated(Request $request, $user)
{
if ( $user->isAdmin() ) {// do your margic here
return redirect()->route('dashboard');
}
return redirect('/home');
}
/**
* Where to redirect users after login.
*
* @var string
*/
//protected $redirectTo = '/admin';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
}
内容总结
以上是互联网集市为您收集整理的php – Laravel 5.4登录后重定向到自定义URL全部内容,希望文章能够帮你解决php – Laravel 5.4登录后重定向到自定义URL所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。