예제 #1
0
 public function store(CreateGroupRequest $request)
 {
     if (Gate::denies('managerOnly')) {
         abort(403);
     }
     $input = $request->all();
     $result = DB::transaction(function ($input) use($input) {
         $group = new Group();
         $group->name = $input['name'];
         $group->organization()->associate(Auth::user()->organization);
         $group->save();
         foreach ($input['users'] as $user) {
             $group->users()->attach($user['id']);
         }
         foreach ($input['indicators'] as $indicator) {
             $group->indicators()->attach($indicator['id']);
         }
         return $group;
     });
     return $result;
 }