/**
  * @param Skill $skill
  * @param Request $request
  * @param Guard $guard
  * @return mixed
  */
 public function update(Skill $skill, Request $request, Guard $guard)
 {
     //save base data for the skill
     $data = translation_input($request, ['name', 'description']);
     $skill->load(['translations']);
     $skill->fill($data);
     $skill->save();
     //attach the skill to the user if needed
     $user = $guard->user();
     if (!$user->skills->contains($skill->id)) {
         $user->skills()->attach($skill);
     }
     //update the pivot data when necessary
     $userSkill = $user->skills()->find($skill->id);
     if ($userSkill) {
         $userSkill->pivot->level = array_get($request->get('pivot'), 'level');
         $userSkill->pivot->save();
     }
     $userSkill->load('translations');
     return $userSkill;
 }
Beispiel #2
0
 protected function baseSkills()
 {
     $teller = 0;
     while ($teller < 10) {
         $skill = ['nl' => ['name' => $this->nl->sentence(rand(1, 2), false), 'description' => $this->nl->paragraph(5)], 'fr' => ['name' => $this->nl->sentence(rand(1, 2), false), 'description' => $this->nl->paragraph(5)], 'en' => ['name' => $this->nl->sentence(rand(1, 2), false), 'description' => $this->nl->paragraph(5)], 'de' => ['name' => $this->nl->sentence(rand(1, 2), false), 'description' => $this->nl->paragraph(5)]];
         Skill::create($skill);
         ++$teller;
     }
     $skills = array_flip([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
     foreach (User::all() as $user) {
         $user->skills()->sync(array_rand($skills, rand(3, 5)));
     }
 }