Laravel Livewire 动态表单数据不工作

Laravel Livewire Dynamic Form Data Not Working

对 Laravel Livewire 很陌生。我正在尝试为应用程序创建一个动态表单,但我不太明白如何在存储 时附加附加数据。 用户选择教师(faculty_id)、学年(sy)和学期(sem)。以及添加更多行的新时间表和选项()

这是来自我的控制器 store() 方法

 public function store()
{
    
    $order = Emp_sched::create([
        'faculty_id'=>$this->faculty_id,
        'sem'=>$this->sem,
        'sy'=>$this->sy,
    ]);

    foreach ($this->createScheds as $sched) {
        $order=(['corsdes' => $sched['corsdes']],
        ['c_time' => $sched['c_time']],  ['day' => $sched['day']],  ['room' => $sched['room']]);
    }


    return 'Schedules Saved!';
}

你必须在循环中调用 Model::create

public function store()
{
    
    foreach ($this->createScheds as $sched) {
        $createArray = array_merge([
                'faculty_id' => $this->faculty_id,
                'sem' => $this->sem,
                'sy' => $this->sy,
            ],[
                'corsdes' => $sched['corsdes'],
                'c_time' => $sched['c_time'],
                'day' => $sched['day'],
                'room' => $sched['room'],
            ]);
            Emp_sched::create($createArray);
    }


    return 'Schedules Saved!';
}