/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id = null)
 {
     if (is_null($id)) {
         $group = new Group();
     } else {
         $group = Group::findOrfail($id);
     }
     $group->designation = Input::get('designation');
     $group->localization = Input::get('localization');
     $group->creation_date = Input::get('creation_date');
     $group->inactivation_date = Input::get('inactivation_date');
     $group->save();
     $years = Input::get('team_coordinator.years');
     if (!is_null($years)) {
         foreach ($years as $year) {
             foreach (['coordinator' => 'Coordenador', 'secretary' => 'Secretario', 'treasurer' => 'Tesoureiro'] as $key => $value) {
                 $group->setRole(Role::role($value), $group->id, $year, (int) Input::get('team_coordinator.' . $year . '.' . $key . '.encontrista.id'));
             }
         }
     }
     return response()->json(['message' => is_null($id) ? 'Successfully created Group!' : 'Successfully updated Group!', 'group' => $group]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(App\Encontrista::class, 50)->create()->each(function ($u) {
         $u->roles()->create(['role_id' => Role::role('Encontrista'), 'group_id' => DB::table('groups')->orderBy(DB::raw('RAND()'))->get()[0]->id]);
     });
 }
Exemple #3
0
 public function getMembersAttribute()
 {
     return $this->members()->whereRoleId(Role::role('Encontrista'))->get();
 }