public function players() { $teamIds = $this->teams->modelKeys(); return Player::whereHas('teams', function ($q) use($teamIds) { $q->whereIn('id', $teamIds); }); }
/** * @test */ public function canDeletePlayer() { $player = Player::first(); $player->guardian->players()->where('players.id', '!=', $player->id)->delete(); $this->assertTrue($player->guardian->isAn(Role::GUARDIAN)); $this->visit('/admin/players/' . $player->id)->press('Delete Player')->see('Player has been deleted'); Bouncer::refresh(); $this->assertTrue($player->guardian->isNotAn(Role::GUARDIAN)); }
/** * @param User $guardian * @param array $attributes * * @return static */ public function create(User $guardian, array $attributes) { $attributes['guardian_id'] = $guardian->id; DB::beginTransaction(); $player = Player::create($attributes); if ($guardian->isNotA(Role::GUARDIAN)) { $role = Role::where('name', Role::GUARDIAN)->firstOrFail(); $guardian->assign($role); } DB::commit(); return $player; }
/** * @param GuardianOnlyRequest $request * @param $id * * @return mixed */ public function update(GuardianOnlyRequest $request, $id) { $rules = Player::validationRules(); $player = Player::findOrFail($id); $isRegistered = $player->isRegisteredWithGroup(Session::season()); if ($isRegistered) { $rules['shirt_size'] = 'required'; $rules['grade'] = 'required'; } $this->validate($request, $rules); $player->update($request->except('shirt_size', 'grade')); if ($isRegistered) { $player->seasons()->updateExistingPivot(Session::season()->id, $request->only(['shirt_size', 'grade'])); } return redirect('/dashboard')->withFlashSuccess('Your changes were saved'); }
/** * @return Player[] */ public function players() { return Player::whereIn('id', $this->eventData())->get(); }
/** * Get players for a given program. * * @return Player[]|Collection */ public function playersWithOptionalProgramSelection() { $playerIds = []; foreach ($this->attributes['players'] as $playerId => $playerData) { if (in_array($playerData['grade'], self::$gradesWithProgramChoice)) { $playerIds[] = $playerId; } } return Player::whereIn('id', $playerIds)->get(); }
/** * @test */ public function editExistingRegistration() { // get a player for this season that is registered $currentSeason = $this->season(); $player = Player::whereHas('seasons', function ($q) use($currentSeason) { $q->where('seasons.id', $currentSeason->id); })->firstOrFail(); $this->guardian = $player->guardian; $this->actingAs($this->guardian); // the test $this->visit('/dashboard')->click('#edit-child-' . $player->id)->select(rand(3, 12), 'grade')->select(array_rand(['S', 'M', 'L', 'XL']), 'shirt_size')->submitForm('Save')->see('Your changes were saved'); }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return Player::where('id', $this->route('player'))->where('guardian_id', Auth::user()->id)->count() > 0; }
/** * @param PlayerInactiveToggleRequest $request * @param $player * * @return mixed */ public function deactivate(PlayerInactiveToggleRequest $request, $player) { $player = Player::findOrFail($player); $player->deactivate(Session::season()); return redirect('/roster')->withFlashSuccess($player->full_name . ' is now inactive'); }
public function destroy(AdminOnlyRequest $request, $playerId) { $player = Player::findOrFail($playerId); $player->delete(); return redirect('/admin/users/' . $player->guardian_id)->withFlashSuccess('Player has been deleted'); }
public static function validationRules() { // check to see if the current user already has a player with this same name // Admins can add duplicate players, but parents can't Validator::extend('guardian_isnt_duplicate_player', function ($attribute, $value, $parameters, $validator) { $data = $validator->getData(); $conditions = ['guardian_id' => Auth::user()->id, 'first_name' => $data['first_name'], 'last_name' => $data['last_name']]; return Player::where($conditions)->count() == 0; }); return ['first_name' => 'required|max:32', 'last_name' => 'required|max:32', 'gender' => 'required', 'birthday' => 'required|date']; }