简体   繁体   English

Laravel 5.7登录表单路线

[英]Laravel 5.7 Login Form Route

I made a fresh install of Laravel 5.7, and I'm trying to change the view it renders when I go to /login . 我重新安装了Laravel 5.7,并尝试更改/login时呈现的视图。

When I list my routes, it says that the route /login uses logic from 'LoginController@showLoginForm', but I can't see it in the controller : 当我列出路线时,它说路线/ login使用'LoginController @ showLoginForm'中的逻辑,但在控制器中看不到它:

php artisan route:list PHP的工匠路线:列表 在此处输入图片说明

and when I go to the LoginController , this showLoginForm method doesn't seem to exist... 当我转到LoginController ,这个showLoginForm方法似乎不存在...

LoginController.php LoginController.php

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{

    use AuthenticatesUsers;

    protected $redirectTo = '/dashboard';

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}

Where is the boilerplate that I can change for this? 我可以为此更改的样板在哪里?

showLoginForm() exists on trait AuthenticatesUsers showLoginForm()存在于特征AuthenticatesUsers

Just try override showLoginForm() method :) 只需尝试覆盖showLoginForm()方法即可:)

class LoginController extends Controller
{

use AuthenticatesUsers;

protected $redirectTo = '/dashboard';

public function __construct()
{
    $this->middleware('guest')->except('logout');
}

public function showLoginForm() {
    // Your code
}
}

it is in : 它在:

use AuthenticatesUsers;

find it and override in loginController 找到它并在loginController中覆盖

this is that code on vendor: 这是供应商上的代码:

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

When you "use AuthenticatesUsers" it extends functionality and also brings the showLoginForm to the controller. 当您“使用AuthenticatesUsers”时,它会扩展功能,并将showLoginForm带到控制器。

If you want to add code to that function you just need to overwrite it. 如果要向该函数添加代码,则只需要覆盖它即可。

If youre using an IDE like PHPStorm you can control click through the "use" declaration to see whats being imported, or you can go manually look inside Illuminate\\Foundation\\Auth\\AuthenticatesUsers 如果您使用类似PHPStorm的IDE,则可以控制单击“使用”声明以查看要导入的内容,也可以手动查看Illuminate \\ Foundation \\ Auth \\ AuthenticatesUsers

登录表单视图位于resources/views/auth/login.blade.php您可以轻松对其进行更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM