php - 在 Laravel 5.6 中登录后更改默认重定向
问题描述
我是laravel的初学者。我正在使用 udemy 视频来学习 laravel。我想在登录后更改默认重定向。我将路线更改为
Route::group(['prefix' => 'admin', 'middleware' => 'auth'],function (){
Route::get('/home', 'HomeController@index')->name('home');
});
并且在Http/Middleware/RedirectIfAuthenticated.php
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/admin/home');
}
return $next($request);
}
但是当我再次登录时,我重定向到/home
而不是/admin/home
. 我清除了缓存,但它不再起作用了。
解决方案
如果您希望重定向只是未经授权的,那么只需编写
Route::group(['prefix' => 'admin', 'middleware' => 'guest'],function (){
Route::get('/home', 'HomeController@index')->name('home');
});
如果你想在登录后重定向到“admin/home”,你可以更改
登录控制器
protected $redirectTo = '/admin/home';
推荐阅读
- python - 在linux中升级python
- c# - c# 获取公共频道 Telegram without Bot Api 和 Telegram Api 的特别帖子
- php - WooCommerce 自定义订单操作不适用于垃圾状态
- azure - 使用 AzureFileCopy 任务覆盖 Azure Blob 存储中的文件
- javascript - 用户事件后的 Wordpress Enqueue 脚本,例如点击
- python - 如何绘制整齐的 ImageGrid 图?
- reactjs - 在单个 Axios POST 请求中发送 FormData 对象和文件
- nginx - 在 NGINX 后面时 Keycloak 无效的重定向 Uri
- excel - VBA如何根据现有列表检查重复值并仅从新列表中添加唯一实例
- json - 如何使用 sagemaker 将 s3 上的大型 json 文件读取到数据帧