如何使用laravel Laravel 8 jetstream在用户注册注册中创建依赖的下拉列表国家、州、城市国家、州和城市。?JetStream?
发布于 2020-12-28 07:36:30
假设您正在使用Livewire +刀片式服务器堆栈,根据官方documentation
这些模板中的每一个都将接收整个经过身份验证的用户对象,以便您可以根据需要向这些表单添加其他字段。添加到表单中的任何其他输入都将包含在传递给UpdateUserProfileInformation操作的$input数组中。
上面的内容意味着你需要一些普通的Laravel,HTML (或者Blade partial)和一个Livewire模型标签。
//app/Models/User.php
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
...
'city', //Assuming new column name is city
...
];在App\Actions\Fortify\UpdateUserProfileInformation操作类中添加任何输入验证逻辑及其将保存到的属性。
//app/Actions/Fortify/UpdateUserProfileInformation.php
$user->forceFill([
...
'city' => $input['city'],
...
])->save();将resources/views/profile/update-profile-information-form.blade.php修改为包含呈现下拉选择框的或部分
//resources/views/profile/update-profile-information-form.blade.php
//Assuming the column name is 'city'
//Assuming you are not using a Blade partial
<div class="col-span-6 sm:col-span-4">
<x-jet-label for="city" value="{{ __('City') }}" />
<select
name="city"
id="city"
class="block w-full mt-1"
wire:model.defer="state.city"
>
<optgroup label="Ontario">
<option value="toronto">Toronto</option>
<option value="markham">Markham</option>
</optgroup>
<optgroup label="Quebec">
<option value="montreal">Montreal</option>
<option value="qc">Quebec City</option>
</optgroup>
</select>请注意,Livewire应该负责通过标记wire:model.defer="state.city“进行的任何数据绑定。
https://stackoverflow.com/questions/65302139
复制相似问题