简体   繁体   English

如何将新输入添加为下拉类型并填充默认选项到 laravel jetstream 注册表单

[英]how to add a new input as a dropdown type and with filled default options to laravel jetstream registration form

my need is to add a new input as a dropdown type and with filled default options to laravel.8 jetstream registration form.我需要添加一个新的输入作为下拉类型,并在 laravel.8 jetstream 注册表单中填充默认选项。 my problems are:我的问题是:

  1. how to add dropdown input to the registration blade file?如何将下拉输入添加到注册刀片文件? use jetstream component or have to create a new component based on livewire or pure laravel component?使用 jetstream 组件还是必须基于 livewire 或纯 laravel 组件创建新组件?
  2. where default options for dropdown must be prepare and sent to the blade file?必须准备下拉菜单的默认选项并将其发送到刀片文件?
  3. how can I get selected options from users in app/Actions/Fortify/CreateNewUser.php?如何从 app/Actions/Fortify/CreateNewUser.php 中的用户那里获得选定的选项? thanks谢谢

I understand this is not a full answer to all of your questions but should help.我知道这不是您所有问题的完整答案,但应该有所帮助。

  1. You can just add a standard select, something like this:您可以添加一个标准的 select,如下所示:
<label for="cars">Choose a car:</label>

<select name="cars" id="cars">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>
  1. You can get/use that value in app/Actions/Fortify/CreateNewUser.php accessing the array.您可以在访问数组的app/Actions/Fortify/CreateNewUser.php中获取/使用该值。 The following inserts the new value into the database:以下将新值插入数据库:
return User::create([
            'name' => $input['name'],
            'email' => $input['email'],
            'car' => $input['cars']),
            'password' => Hash::make($input['password']),
            'api_token' => Str::random(60),
        ]);

You will also need to update the app/Models/User.php Model and add the new value as fillable (and of course have added the field to your User Model via a migration):您还需要更新app/Models/User.php Model 并将新值添加为可填写(当然,已通过迁移将该字段添加到您的User ZA559B87068921EEC05086CE5485E974):

protected $fillable = [
        'name',
        'email',
        'password',
        'car',
    ];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM