我希望我的項目有兩種登錄方式,使用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. 我應該怎么辦?
1 回答

慕容708150
TA貢獻1831條經驗 獲得超4個贊
這個怎么樣:
基本上,您需要一種方法來告訴輸入是電話號碼還是用戶名,這里是一個檢查輸入是電話號碼的示例,這很簡單,您可能需要根據您的特定需要進行修改。
$fieldType = ctype_digit($login) ? 'phone' : 'korisnicko_ime';
- 1 回答
- 0 關注
- 133 瀏覽
添加回答
舉報
0/150
提交
取消