Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

laravel - Bleaching the page when submitting the form with livewire

In login form i used livewire and when i out focus of phone field my webpage its been white

please help me thanks <3

view code:

<form wire:submit.prevent="login">
   <fieldset class="form-label-group form-group position-relative has-icon-left">
   <input wire:model.debounce.500ms="phone" type="text" class="form-control" id="phone" placeholder="????? ????">
   <div class="form-control-position">
       <i class="feather icon-phone"></i>
   </div>
   <label for="phone">????? ????</label>
   </fieldset>
   @error('phone') <span class="text-danger">{{ $message }}</span> @enderror

   <button type="submit" class="btn btn-primary float-left btn-inline" wire:click.prevent="login">????</button>
</form>

controller code:

class Login extends Component { public $phone;

protected $rules = [
    'phone' => ['required', 'regex:/^09(1[0-9]|3[1-9]|2[1-9])-?[0-9]{3}-?[0-9]{4}$/', 'exists:users,phone']
];
public function updatedPhone($name)
{
    $this->validate($name);
}

public function login(Request $request)
{
    $validData = $this->validate();

    $user = User::wherePhone($validData['phone'])->first();
    dd($user);
    $request->session()->flash('auth', [
        'user_id' => $user->id,
        'remember' => $request->has('remember'),
    ]);

    $code = ActiveCode::generateCode($user);

    $user->notify(new ActiveCodeNotification($code, $user->phone));
    dd('done');
}

public function render()
{
    return view('livewire.auth.login')
            ->layout('livewire.auth.layouts.layouts');
}

}

question from:https://stackoverflow.com/questions/66062222/bleaching-the-page-when-submitting-the-form-with-livewire

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your updatePhone method is supposed to receive $value from input binded with wire:model so you have to pass a key-value to validate method:

public function updatePhone($value)
{
  $this->validate($this->rules); // protected prop with key-value rules defined
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...