Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel Livewire Dynamic Form Data Not Working

Quite new to Laravel Livewire. I’m trying to create a dynamic form for application but I couldn’t quite understand how to attach additional data when storing.
The user selects the instructor(faculty_id), schoolyear(sy) and semester(sem). And new schedule and option to add more rows()

This is from my controller store() method

 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!';
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You must call Model::create inside loop

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!';
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading