From 7d5d59dc0ceede03f6d27a2ab8650aebb800c618 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 23 Jun 2021 01:45:48 +0200 Subject: [PATCH] Validate fee_id --- app/Member/MemberRequest.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Member/MemberRequest.php b/app/Member/MemberRequest.php index 37cb6249..3fc5a0f6 100644 --- a/app/Member/MemberRequest.php +++ b/app/Member/MemberRequest.php @@ -5,6 +5,9 @@ namespace App\Member; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; use App\Group; +use Illuminate\Support\Str; +use App\Activity; +use Illuminate\Support\Arr; class MemberRequest extends FormRequest { @@ -28,6 +31,15 @@ class MemberRequest extends FormRequest return [ 'first_activity_id' => Rule::requiredIf(fn() => $this->method() == 'POST'), 'first_subactivity_id' => Rule::requiredIf(fn() => $this->method() == 'POST'), + 'fee_id' => Rule::requiredIf(function() { + if ($this->method() != 'POST') { + return false; + } + + if (!$this->input('first_activity_id')) { return true; } + + return Str::contains(Activity::findOrFail($this->input('first_activity_id'))->name, '€'); + }), 'firstname' => 'required', 'lastname' => 'required', 'address' => 'required', @@ -51,6 +63,13 @@ class MemberRequest extends FormRequest } public function persistUpdate(Member $member) { - $member->update($this->input()); + $member->update(Arr::except($this->input(), ['first_activity_id', 'first_subactivity_id'])); + + if($this->input('has_nami') && $member->nami_id === null) { + CreateJob::dispatch($member, auth()->user()); + } + if($this->input('has_nami') && $member->nami_id !== null) { + UpdateJob::dispatch($member, auth()->user()); + } } }