现在的登录页面是这样的:

填上正确的 email密码 就可以登录。

现在我们需要用之前创建的 username 代替 email 来登录。

第一步是先来改 view。

找到登录页面的 view 文件:resources/views/auth/login.blade.php

再找到下面这部分:

<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
    <label for="email" class="col-md-4 control-label">E-Mail Address</label>

    <div class="col-md-6">
        <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>

        @if ($errors->has('email'))
            <span class="help-block">
                <strong>{{ $errors->first('email') }}</strong>
            </span>
        @endif
    </div>
</div>

把它改一下,改成下面这样:

<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
    <label for="username" class="col-md-4 control-label">UserName</label>

    <div class="col-md-6">
        <input id="username" type="text" class="form-control" name="username" value="{{ old('username') }}" required autofocus>

        @if ($errors->has('username'))
            <span class="help-block">
                <strong>{{ $errors->first('username') }}</strong>
            </span>
        @endif
    </div>
</div>

改了 view 还不够,还要再改一个地方:

第二步,找到 app/Http/Controllers/Auth/LoginController.php 文件,打开之后,添加下面这个方法:

public function username()
{
    return 'username';
}

最终的效果:

results matching ""

    No results matching ""