samedi 10 avril 2021

Method Illuminate\Http\Request::array does not exist

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(
        'staff' => 'array|required',
        'staff_id' => 'required',
        'staff.*.task_id' => 'required',
        'done_at' => 'sometimes',
    ));

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

        $assignment = Assignment::create(array(
            'staff_id' => $request->array('staff_id'),
            'task_id' => $assignment['task_id'],
            'done_at' => 'null',
        ));
        return redirect()->route('assignments.index', compact('assignment'))->withSuccess('Done');
}

This is my Create page where is form and its giving error on submitting (This is my Create page where is form and its giving error on submitting)

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

                                <option value=""></option>

                            @endforeach
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Staff Name : </td>
                    <td>
                        <select name="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>
            @endforeach
            <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