i have two tables group(parent) and users(kid) . I can read data from each group but i want to show them inside a multiselect so i can remove or add more users to the group and update.
Group controller:
  public function edit($id)
   {
   //
   $group= Group::find($id);
   $users = User::where('group_id',$id)->get();
   return view('group.edit',compact('group','users'));
 }
 public function update(Request $request, $id)
 {
 $request->validate([
 'name'=> 'required',
 'group_id' => 'required|array',
 ]);
 $group = Group::find($id);
 $group ->name = $request->get('name');
       //something missing/wrong here
 $group->save();
 return redirect('/groups')->with('success', 'Group has been edited');
 }
User model:
public function group()
{
    return $this->belongsTo('App\Group');
}
Group model
 public function users()
{
    return $this->hasMany('App\User','group_id');
}
edit view:
<form method="post" action="{{ route('groups.update', $group->id) }}">
    @method('PATCH')
    @csrf
    <div class="form-group">
      <label for="name">Name:</label>
      <input type="text" class="form-control" name="name" value={{ $group->name }} />
    </div>
    <div class="form-group">
        <select name="group_id[]" id="users" class="form-control"  multiple>
            @foreach ($users as $user)
            <option value="{{$user->id}}">{{$user->name}}</option>
            @endforeach
        </select>
        </div>
    <a href="{{url()->previous()}}" class="pull-right btn btn-danger" >Cancel</a>
    <button type="submit" class="pull-right btn btn-primary" style="margin-right:5px;">Update</button>
  </form>
Database structure:
Groups table:
id
name
Users table:
id
name
email
group_id
Im using select2 package and this is what im trying to make :
Thanks
 
     
    