如何更改默认的 Laravel Auth 登录视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40818801/
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 14:49:20  来源:igfitidea点击:

How to change default Laravel Auth login view

phplaravellaravel-5.3

提问by StevenThelin

I'm trying to change the default login view, from Laravel Auth. Earlier suggestions points at modifying the path inside of the corresponding controller, under /vendor. However, this is a cooperative project, so modifying the vendor files is not an option.

我正在尝试从 Laravel Auth 更改默认登录视图。较早的建议指向修改 /vendor 下相应控制器内部的路径。但是,这是一个合作项目,因此修改供应商文件不是一种选择。

By default the view for Auth login is auth.login, but i want it to be backend.pages.login.

默认情况下,Auth 登录的视图是auth.login,但我希望它是backend.pages.login

In which other way can i accomplish this?

我可以通过哪种其他方式完成此任务?

I have also tried to manually add the view routes in the router, but it won't recognize Authas a class, no matter how i wire it up.

我还尝试在路由器中手动添加视图路由,但Auth无论我如何连接它,它都不会识别为一个类。

Note: It's Laravel 5.3

注意:这是 Laravel 5.3

Thanks in advance

提前致谢

回答by Amit Gupta

In App\Http\Controllers\Auth\LoginControllerdefine a fuction named showLoginForm()as:

App\Http\Controllers\Auth\LoginController定义一个名为的函数showLoginForm()

public function showLoginForm()
{
    return view('custom.login');
}

It overrides the function showLoginFormdefined in the trait Illuminate\Foundation\Auth\AuthenticatesUsers.

它覆盖showLoginForm了 trait 中定义的函数Illuminate\Foundation\Auth\AuthenticatesUsers

Note: In Laravel 5.3 the function name is changed from getLoginto showLoginForm.

注意:在 Laravel 5.3 中,函数名称由 更改getLoginshowLoginForm

回答by Md. Abu Taleb

in your AuthenticatesUsers trait override this method :

在您的 AuthenticatesUsers 特征中覆盖此方法:

public function showLoginForm()
{
    return view('login');
}

回答by A. Dady

Since the question was already answered I'll give the same example for the current version of Laravel.

由于问题已经得到回答,我将为当前版本的 Laravel 提供相同的示例。

If you're on Laravel 5.6 and up, this functionality should be put in

如果您使用的是 Laravel 5.6 及更高版本,则应加入此功能

app/Http/Controllers/Auth/LoginController.php

app/Http/Controllers/Auth/LoginController.php

public function showLoginForm()
{
    return view('custom.login');
}

Also, if you would like to add a parameter to this, you can do so if you specify it in your web route like this:

此外,如果您想为此添加一个参数,您可以在您的网络路由中指定它,如下所示:

Route::get('login/{page?}', 'Auth\LoginController@showLoginForm')->name('login');

Then you can do something like this:

然后你可以做这样的事情:

public function showLoginForm($page = null)
{
    if(isset($page)){
        // do something
        // example: return view('auth.login', compact('page'));
    }
    return view('auth.login');
}

Tip: if you don't have the LoginController in your project make sure you run

提示:如果您的项目中没有 LoginController,请确保您运行

php artisan make:auth

回答by Prajakta Pawar

Add below lines in routes/web.php

在 routes/web.php 中添加以下几行

Route::get('/', function () {
    return view('auth.login');
});