can(Permissions::INBOX_MAILER->value); } /** * Get the validation rules that apply to the request. * * @return array|string> */ public function rules(): array { return [ 'title' => 'required|string', 'body' => 'required|string', 'tag' => 'required|string', 'expireAt' => 'nullable|date', 'rewards' => 'sometimes|array', 'users' => [Rule::requiredIf(!$this->has('allUsers')), 'array'], 'allUsers' => 'sometimes', ]; } protected function passedValidation(): void { $this->title = $this->input('title'); $this->body = $this->input('body'); $this->tag = $this->input('tag'); $this->expireAt = $this->input('expireAt') === null ? null : new Carbon($this->input('expireAt')); $this->users = $this->input('users'); $this->allUsers = $this->has('allUsers'); $rewardTypes = $this->input('rewards.type'); $rewardIds = $this->input('rewards.id'); $rewardAmounts = $this->input('rewards.amount'); if($rewardIds === null) return; foreach ($rewardIds as $index => $id) { $this->rewards[] = new InboxMessageReward( $rewardTypes[$index], $rewardAmounts[$index], $id, ); } } }