0

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

1 Answer 1

1

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!';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.