Laravel 5 - 抱歉,找不到您要找的页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41411645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:01:59  来源:igfitidea点击:

Laravel 5 - Sorry, the page you are looking for could not be found

laravelredirectloginrouting

提问by Tower

I am trying to redirect the Laravelpage to another other that home after login, but it redirects me to homeevery time. What I've done is: I changed the value of protected $redirectTo =from hometo protected $redirectTo = 'S1CheckUserTables';.
I also defined my route in web.phpas follows (I beleived that I shall use a named route):

我试图Laravel在登录后将页面重定向到另一个主页,但它home每次都将我重定向到。我所做的是:我将protected $redirectTo =from的值更改homeprotected $redirectTo = 'S1CheckUserTables';
我还web.php如下定义了我的路线(我相信我将使用命名路线):

Route::get('/S1CheckUserTables', ['as'=>'S1CheckUserTables', 'uses'=>'S1CheckUserTablesController@index']);

I also tried using the following syntax to fix the issue but it didn't work either:

我也尝试使用以下语法来解决问题,但它也不起作用:

Route::get('S1CheckUserTables', 'S1CheckUserTablesController@index')->name('S1CheckUserTables');

Would you please tell me what could solve my problem? Thank you very much in advance.

你能告诉我什么可以解决我的问题吗?非常感谢您提前。

采纳答案by lewis4u

Default redirect for laravel after login is to go to /home set in the LoginController:

登录后 Laravel 的默认重定向是转到 LoginController 中设置的 /home:

use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

and there is default middleware RedirectIfAuthenticated

并且有默认的中间件 RedirectIfAuthenticated

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect('/home');
        }

        return $next($request);
    }
}

and in app/Http/Controllers/Auth/RegisterController.php

并在 app/Http/Controllers/Auth/RegisterController.php

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

So that is where you need to make changes in order to work your way...

因此,这就是您需要进行更改以按自己的方式工作的地方...