亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel - 使用電話和用戶名登錄,FILTER_VALIDATE_EMAIL ISSUE

Laravel - 使用電話和用戶名登錄,FILTER_VALIDATE_EMAIL ISSUE

PHP
不負相思意 2023-11-05 15:21:27
我希望我的項目有兩種登錄方式,使用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';


查看完整回答
反對 回復 2023-11-05
  • 1 回答
  • 0 關注
  • 133 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號