/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $vocations = vocations(true)->map(function (&$vocation) { $vocation = $vocation->id(); })->keys()->implode(','); return ['vocation' => ['required', 'in:all,' . $vocations], 'group' => ['required', 'in:all,attack,healing,support'], 'type' => ['required', 'in:all,instant,conjure,rune'], 'premium' => ['required', 'in:all,no,yes'], 'sort' => ['required', 'in:name,group,type,level,mana,premium']]; }
/** * Execute the job. * * @param \Illuminate\Http\Request $request * @return \Apolune\Contracts\Account\Player|null */ public function handle(Request $request) { $player = app('player'); $player->name = ucwords(strtolower($request->get('player'))); $player->account_id = $this->account->id(); $player->vocation = $request->get('vocation', vocations(true)->first()->id()); $player->town_id = $request->get('town', towns(true)->first()->id()); $player->world_id = $request->get('world', worlds()->first()->id()); $player->sex = $request->get('sex', genders()->first()->id()); $player->conditions = ''; $player->save(); event(new Created($player, $this->account)); return $player; }
/** * Process the search criteria for the spells page. * * @param \Apolune\Library\Http\Requests\Spells\FormRequest $request * @return \Illuminate\Http\Response */ public function form(FormRequest $request) { if ($request->has('spell')) { return redirect(url('/library/spells', $request->get('spell')))->withInput(); } extract($this->getCriteria($request)); $spells = spells(); // Filter by vocation if (strtolower($vocation) !== 'all') { $spells = $spells->filter(function ($spell) use($vocation) { $vocations = vocations(true)->filter(function ($vocation) use($spell) { return in_array($vocation->name(), $spell->vocations()); })->map(function (&$item) { $item = $item->id(); })->keys(); return in_array((int) $vocation, $vocations->toArray()); }); } // Filter by group if (strtolower($group) !== 'all') { $spells = $spells->filter(function ($spell) use($group) { return strtolower($spell->group()) === strtolower($group); }); } // Filter by type if (strtolower($type) !== 'all') { $spells = $spells->filter(function ($spell) use($type) { return strtolower($spell->type()) === strtolower($type); }); } // Filter by premium status if (strtolower($premium) !== 'all') { $spells = $spells->filter(function ($spell) use($premium) { return $spell->premium() === (strtolower($premium) === 'yes'); }); } $sorted = $spells->sort(function ($a, $b) use($sort) { return $a->{$sort}() > $b->{$sort}(); }); return redirect('/library/spells')->with('spells', $sorted)->withInput(); }
/** * Get a specific vocation. * * @param integer $id * @param boolean $starter null * @return \Apolune\Contracts\Server\Vocation */ function vocation($id, $starter = null) { $vocations = vocations($starter); return head(array_where($vocations, function ($key, $vocation) use($id) { return $vocation->id() === (int) $id; })); }