【问题标题】:I am using livewire with Laravel 8 for insertion of a form into my database and I am getting the following error我在 Laravel 8 中使用 livewire 将表单插入到我的数据库中,我收到以下错误
【发布时间】:2021-06-03 02:59:34
【问题描述】:

我在 Laravel 8 中使用 livewire 将表单插入到我的数据库中,我收到以下错误。我尝试对等级变量进行 json 编码,但我无法解决问题。

//my insertion view
      <div >
                            <select class="form-control" id="select2-dropdown">
                                <option value="">Select Option</option>
                                <option value="{{ $item }}">{{ $item }}</option>
                                @foreach($grade as $item)

                                    <option value="{{ $item }}">{{ $item }}</option>
                                @endforeach

                            </select>
                        </div>


//inside livewire/wizard


class Wizard extends Component
{
    public $currentStep = 1;
    public $first_name, $price, $detail,$middle_name,
 
    public $grade = [
        'one',
        'two',
        'Three',
        'Four'
    ];
public function submitForm()
    {
        Student::create([
          
           
            'grade' =>$this->grade
            
        ]);

【问题讨论】:

    标签: database forms input dropdown laravel-8


    【解决方案1】:

    在刀片中

    <select class="form-control" id="select2-dropdown" wire:model="selectedItem">  // wire:model bind to the property
       <option value="">Select Option</option>
       @foreach($grade as $item)
         <option value="{{ $item }}">{{ $item }}</option>
       @endforeach
    </select>
    

    在组件中

    public $selectedItem;
    public $grade = [
            'one',
            'two',
            'Three',
            'Four'
    ];
    public function submitForm()
    {
      Student::create([       
        'grade' =>$this->selectedItem
      ]);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-11-02
      • 2015-10-31
      • 2018-06-27
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 2018-11-24
      • 1970-01-01
      • 2017-11-02
      相关资源
      最近更新 更多