Validate fee_id

This commit is contained in:
philipp lang 2021-06-23 01:45:48 +02:00
parent d7591a7055
commit 7d5d59dc0c
1 changed files with 20 additions and 1 deletions

View File

@ -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());
}
}
}