我希望我的项目有两种登录方式,使用phone或 使用username = korisnicko_ime. 这就是我所做的LoginController:
/**
* Login username to be used by the controller.
*
* @var string
*/
protected $username;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->username = $this->findUsername();
}
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function findUsername()
{
$login = request()->input('login');
$fieldType = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'korisnicko_ime';
request()->merge([$fieldType => $login]);
return $fieldType;
}
/**
* Get username property.
*
* @return string
*/
public function username()
{
return $this->username;
}
我的性格也发生了public function username()这样AuthenticatesUsers的变化:
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return 'phone';
}
我的刀片看起来像这样:
<div class="form-group row">
<label for="login" class="col-sm-4 col-form-label text-md-right">
{{ __('Username or Phone') }}
</label>
<div class="col-md-6">
<input id="login" type="text" class="form-control{{ $errors->has('korisnicko_ime') || $errors->has('phone') ? ' is-invalid' : '' }}" name="login" value="{{ old('korisnicko_ime') ?: old('phone') }}" required autofocus>
@if ($errors->has('korisnicko_ime') || $errors->has('phone'))
<span class="invalid-feedback">
<strong>{{ $errors->first('korisnicko_ime') ?: $errors->first('phone') }}</strong>
</span>
@endif
</div>
</div>
问题出在这部分代码中:
$fieldType = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'korisnicko_ime';
如果我更改email为phone并删除FILTER_VALIDATE_EMAIL,那么我只能使用 my 登录phone,而不能使用korisnicko_ime. 我应该怎么办?
慕容708150