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',