【发布时间】:2020-10-17 21:53:24
【问题描述】:
我对 Vue.js 一点也不熟悉,所以用 Livewire 找到了一个很好的替代品。
我必须解决的挑战是使用 Fortify + Livewire 在我的网站上进行用户友好的注册。注册过程是一个多步骤的过程,取决于用户做出的选择,它将加载相关字段。
到目前为止,我通过在 FortifyServiceProvider.php 文件中添加以下代码来设置 Fortify 视图:
Fortify::loginView(function () {
return view('auth.login');
});
Fortify::registerView(function () {
return view('auth.register');
});
auth/login.blade.php 视图加载 livewire 组件,它基本上是一个表单:
<form action="{{ route('register') }}" method="POST" wire:submit.prevent="submit">
/**
* Here would go the inputs that must be shown depends on what users choice
* (is it an ordinar user or a company)
*/
<button type="submit">Save<button/>
</form>
可以通过将$step 属性添加到Register.php 类中来解决多形式挑战:
class RegisterForm extends Component
{
public $step;
public function mount()
{
$this->step = 0;
}
public function submit()
{
if ($this->step < 3) {
$this->step++;
} else {
// pass all the data to the fortify register method
// <-- Here is my trouble!
}
}
}
通过每个注册步骤 ($this->step++) 将递增。
对我来说相当复杂的最重要的事情是如何防止表单提交进行验证+表单更改以及最终所有数据集通过 Fortify 注册过程?
【问题讨论】:
标签: laravel fortify laravel-livewire custom-authentication