Php Laravel 5.3继续前往/主视图
请帮助我解决此身份验证重定向问题 目前我使用的是laravel 5.3.22。我已经把Php Laravel 5.3继续前往/主视图,php,laravel,laravel-5.3,Php,Laravel,Laravel 5.3,请帮助我解决此身份验证重定向问题 目前我使用的是laravel 5.3.22。我已经把 protected $redirectTo = 'dashboard'; 进入我的登录控制器 然后在浏览器中测试重定向: http://myapp.localhost/login 它正确显示“登录页面”。然后我继续登录,它将我重定向到“仪表板”正确 问题就在这里。成功登录后,如果我尝试转到 http://myapp.localhost/login 它将我重定向到“Home”,但它不可用。应该转到“仪表板
protected $redirectTo = 'dashboard';
进入我的登录控制器
然后在浏览器中测试重定向:
http://myapp.localhost/login
它正确显示“登录页面”。然后我继续登录,它将我重定向到“仪表板”正确
问题就在这里。成功登录后,如果我尝试转到
http://myapp.localhost/login
它将我重定向到“Home”,但它不可用。应该转到“仪表板”
请帮助我。您需要将路由添加到routes.php 首先创建 1-带有Artisan php make::HomeController的控制器 2-在app dir route::get('/home',函数(){return view('home');})中添加路由;
3-稍后您需要在目录resources/views/home.blade.php中创建一个名为home.blade.php的页面,您需要将路由添加到routes.php 首先创建 1-带有Artisan php make::HomeController的控制器 2-在app dir route::get('/home',函数(){return view('home');})中添加路由; 3-稍后,您需要在目录resources/views/home.blade.php中创建一个名为home.blade.php的页面。。。 你清除过缓存吗
$ php artisan cache:clear
$ php artisan config:clear
$ php artisan clear-compiled
如果未成功执行上述步骤,请跳到以下方法:LoginController使用AuthenticatesUsers
trait,它使用RedirectsUsers
trait,它拥有redirectPath()
方法。在这种情况下,您可以这样覆盖它:
public function redirectPath()
{
return '/Dashboard';
}
正如您可能已经想到的,您必须将该代码段放入LoginController。这就是wierd。。。
你清除过缓存吗
$ php artisan cache:clear
$ php artisan config:clear
$ php artisan clear-compiled
如果未成功执行上述步骤,请跳到以下方法:LoginController使用AuthenticatesUsers
trait,它使用RedirectsUsers
trait,它拥有redirectPath()
方法。在这种情况下,您可以这样覆盖它:
public function redirectPath()
{
return '/Dashboard';
}
正如您可能已经了解的,您必须将代码段放入LoginController。请查看
文件夹/app/http/Middleware/
,您应该会看到以下文件RedirectIfAuthenticated.php
更改为:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
return $next($request);
致:
你应该没事的
请注意
/app/Controllers/Auth/LoginController.php
指示登录后发送到的位置,而
/app/Middleware/RedirectIfAuthenticated.php
控制在成功登录后请求的
domain.app/login
请求中向用户发送的位置。请查看文件夹/app/http/Middleware/
中的以下文件RedirectIfAuthenticated.php
更改为:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
return $next($request);
致:
你应该没事的
请注意
/app/Controllers/Auth/LoginController.php
指示登录后发送到的位置,而
/app/Middleware/RedirectIfAuthenticated.php
控制在
域中发送用户的位置。成功登录后请求app/login
请求。安装Laravel后,检查数据库中是否存在表用户,如果不存在,则检查会话-您需要执行命令php artisan migrate来创建表!或php artisan make_Auth感谢您的帮助。但我需要重定向到“仪表板”而不是“主页”。成功登录进程后,它将正确重定向到仪表板。但如果我已经登录,那么我会手动转到http://myapp.localhost/login
它将我重定向到http://myapp.localhost/home
而不是http://myapp.localhost/dashboard
Route::get('/dasboard',function(){returnview('dashborad');});Route::group(['middleware'=>'auth'],function(){Route::get('/dasboard',function(){return view('dashborad');});});最后一条路线,如果您是loggedin,则在安装Laravel后重定向到仪表板(Y),检查数据库中是否存在表用户,如果没有出现,则检查会话-您需要执行命令php artisan migrate来创建表!或php artisan make_Auth感谢您的帮助。但我需要重定向到“仪表板”而不是“主页”。成功登录进程后,它将正确重定向到仪表板。但如果我已经登录,那么我会手动转到http://myapp.localhost/login
它将我重定向到http://myapp.localhost/home
而不是http://myapp.localhost/dashboard
Route::get('/dasboard',function(){returnview('dashborad');});Route::group(['middleware'=>'auth'],function(){Route::get('/dasboard',function(){return view('dashborad');});});最后一个路由(如果您是loggedin)重定向到仪表板(Y)您是否编辑了中间件?原因默认情况下“RedirectIfAuthenticated.php”当用户尝试登录页面时,此中间件将用户重定向到主页。当用户登录时,中间件就是答案。您是否编辑了中间件?原因默认情况下“RedirectIfAuthenticated.php”当用户尝试登录页面时,此中间件将用户重定向到主页。当用户登录时,中间件就是答案。是的,这就是问题的根源。谢谢你的帮助。我已经测试了代码,现在它正确地将我重定向到http://myapp.localhost/dashboard
如果用户已登录。是,这就是问题的根源。谢谢你的帮助。我已经测试了代码,现在它正确地将我重定向到http://myapp.localhost/dashboard
如果用户已登录。