samedi 10 avril 2021

Undefined variable $key

This is my AssignmentController Store function. (This is my AssignmentController Store function.) This is my AssignmentController Store function. (This is my AssignmentController Store function.)

public function store(Request $request)
{
    $request->validate(array(
        'assignment' => 'array|required',
        'assignment.*.staff_id' => 'required',
        'assignment.*.task_id' => 'required',
        'done_at' => 'sometimes',
    ));

    foreach($request->get('assignment') as $assignment)

        $assignment = Assignment::create(array(
            'staff_id' => $assignment['staff_id'],
            'task_id' => $assignment['task_id'],
            'done_at' => $assignment['done_at'],
        ));



        return redirect()->route('assignments.index')->withSuccess('Done');
}

This is my assignment.create page (This is my assignment.create page This is my assignment.create page )

<form method="post" action="">
        @csrf
        <table>
                <tr>
                    <td>Task Title : </td>
                    <td>
                        <select name="assignment[][task_id] " id="task_id">
                            
                            @foreach ($tasks as $task)

                                <option value=""></option>

                            @endforeach
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Staff Name : </td>
                    <td>
                        <select name="assignment[][staff_id]" id="staff_id" multiple>
                            
                            @foreach ($staffs as $staff)

                                <option value=""></option>

                            @endforeach
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Done At :</td>
                    <td><input type="time" name="done_at" class="form-control"></td>
                </tr>
            <td><button class="btn btn-primary" name="submit" type="submit" value="submit" id="submit">Submit</button></td>
        </table>
    </form>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire