From 42ac6ee7a16f28211e3b4a92a6f6a108d6b73e40 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 30 Oct 2021 00:50:03 +0200 Subject: [PATCH] Add last_remembered_at date to new payments --- app/Member/Member.php | 7 +++++++ app/Payment/AllpaymentController.php | 2 +- app/Payment/PaymentController.php | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Member/Member.php b/app/Member/Member.php index d746c531..862a1995 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -58,6 +58,13 @@ class Member extends Model $this->update(['version' => $version]); } + public function createPayment(array $attributes): void + { + $this->payments()->create(array_merge($attributes, [ + 'last_remembered_at' => now(), + ])); + } + //----------------------------------- Getters ----------------------------------- public function getFullnameAttribute(): string { return $this->firstname.' '.$this->lastname; diff --git a/app/Payment/AllpaymentController.php b/app/Payment/AllpaymentController.php index 3a893dc2..167436ec 100644 --- a/app/Payment/AllpaymentController.php +++ b/app/Payment/AllpaymentController.php @@ -23,7 +23,7 @@ class AllpaymentController extends Controller ]); foreach (Member::payable()->whereNoPayment($request->year)->get() as $member) { - $member->payments()->create([ + $member->createPayment([ 'nr' => $request->year, 'subscription_id' => $member->subscription_id, 'status_id' => Status::default(), diff --git a/app/Payment/PaymentController.php b/app/Payment/PaymentController.php index fc189fbf..92a121c8 100644 --- a/app/Payment/PaymentController.php +++ b/app/Payment/PaymentController.php @@ -21,7 +21,7 @@ class PaymentController extends Controller } public function store(Request $request, Member $member) { - $member->payments()->create($request->validate([ + $member->createPayment($request->validate([ 'nr' => 'required|numeric', 'subscription_id' => 'required|exists:subscriptions,id', 'status_id' => 'required|exists:statuses,id',