How to give task to multiple users by filling same form in laravel?

  eloquent, laravel, laravel-5, laravel-7, laravel-8

i make a task manager for practice. I have 1 query that how can i assign task to multiple users by filling 1 form

This is my TaskController

public function store(Request $request)
        'staff_id' => 'required',
        'task' => 'required',
        'done_at' => 'sometimes',

    $task = Task::create([
        'staff_id' => $request->input('staff_id'),
        'task' => $request->input('task'),
        'done_at' => $request->input('done_at'),

    return redirect()->route('tasks.index')->withSuccess('Done');
public function complete($id)
    $task = Task::find($id);
    if ($task->done_at !== null) {
        $task->done_at = null;

    } else {
        $task->done_at = now();


This is my task model the task model having relation with another table name staffs

use HasFactory;

protected $fillable = [

public function staff()
    return $this->belongsTo(Staff::class);

This is my create page where there is a form

<form method="post" action="{{route('')}}">
                    <td>Staff Name : </td>
                        <select name="staff_id" id="staff_id">
                            <option value="">Select One</option>
                            @foreach ($staffs as $staff)

                                <option value="{{ $staff->id }}">{{ $staff->name }}</option>

                    <td>Task : </td>
                    <td><input type="text" name="task" class="form-control"></td>
                    <td>Done At :</td>
                    <td><input type="time" name="done_at" class="form-control"></td>
            <td><button class="btn btn-primary" name="submit" type="submit" value="submit" id="submit">Submit</button></td>

and this is my tasks table and this is my tasks table and this is my tasks table and this is my tasks table.

Schema::create('tasks', function (Blueprint $table) {

Source: Laravel

Leave a Reply