dimanche 11 avril 2021

separate each value with comma from multiple select in laravel

I make task manager there is a form where to assign task I want to do that if user select multiple option then it is seperated by comma

This is my form

<form method="post" action="">
        @csrf
        <table>
                <tr>
                    <td>Task Title : </td>
                    <td>
                        <select name="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" multiple>
                            <option value=null>Select One</option>
                            @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">Submit</button></td>
        </table>
    </form>

And this is my store function from where I storing the data recieved from form

$request->validate([
        'staff_id' => 'required',
        'task_id' => 'required',
        'done_at' => 'sometimes',
    ]);
    $assignment = new Assignment();
    $assignment->staff_id = $request->staff_id;
    $assignment->task_id = $request->task_id;
    $assignment->done_at = $request->done_at;
    $assignment->save();
    return redirect()->route('assignments.index', compact('assignment'))->withSuccess('Done');


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3tcEFWq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire