TASKS 12: Membership Extensions & Payment Tracking - RadLeoOFC/laravel-admin-panel GitHub Wiki
The objective of this task was to allow users to extend their membership (renew) and track payments within the existing memberships table without creating a separate payments table.
A new migration file was created to add payment-related columns (amount_paid, payment_status, payment_method, and transaction_reference) to the memberships table.
Migration Execution Command:
php artisan make:migration add_payment_fields_to_memberships_table --table=memberships
Executed Migration:
php artisan migrate
Screenshot: Successful migration execution.

- The Membership model was updated to include the new fields in the $fillable array to allow mass assignment.
Screenshot: Updated Membership model.

- A button was added in the
index.blade.phpfile to allow users to extend their membership.
<form action="{{ route('memberships.extend', $membership->id) }}" method="POST">
@csrf
<button type="submit" class="btn btn-primary">Продлить членство</button>
</form>Screenshot: Membership extension button on the page.

- A new route was added in routes/web.php to handle the membership extension request.
Route::post('/memberships/{id}/extend', [MembershipController::class, 'extend'])->name('memberships.extend');Screenshot: Updated routes file

A method extend was added to the MembershipController to update the membership expiration date when the user clicks the "Extend Membership" button.
public function extend(Request $request, $id)
{
$membership = Membership::findOrFail($id);
// Extend membership for another period (e.g., 1 month)
$membership->end_date = \Carbon\Carbon::parse($membership->end_date)->addMonth();
$membership->payment_status = 'pending'; // Mark payment as pending until paid
$membership->save();
return redirect()->back()->with('success', 'Membership extended successfully!');
}Screenshot: Membership extension method code

A method updatePaymentStatus was added to MembershipController to update payment-related details.
public function updatePaymentStatus(Request $request, $id)
{
$membership = Membership::findOrFail($id);
$membership->amount_paid = $request->amount_paid;
$membership->payment_status = $request->payment_status;
$membership->payment_method = $request->payment_method;
$membership->transaction_reference = $request->transaction_reference;
$membership->save();
return redirect()->back()->with('success', 'Payment details updated successfully!');
}Screenshot: Payment status update method code

A corresponding route was added:
Route::post('/memberships/{id}/update-payment', [MembershipController::class, 'updatePaymentStatus'])->name('memberships.updatePayment');
A new form was added to allow users to update payment details.
<!-- Payment Update Form -->
<form action="{{ route('memberships.updatePayment', $membership->id) }}" method="POST" class="mt-2">
@csrf
<div class="input-group input-group-sm">
<input type="number" name="amount_paid" placeholder="Amount" class="form-control" required>
<select name="payment_status" class="form-select">
<option value="pending" {{ $membership->payment_status == 'pending' ? 'selected' : '' }}>Pending</option>
<option value="paid" {{ $membership->payment_status == 'paid' ? 'selected' : '' }}>Paid</option>
<option value="failed" {{ $membership->payment_status == 'failed' ? 'selected' : '' }}>Failed</option>
</select>
<input type="text" name="payment_method" placeholder="Payment Method" class="form-control">
<input type="text" name="transaction_reference" placeholder="Transaction Ref" class="form-control">
<button type="submit" class="btn btn-success">Update</button>
</div>
</form>Screenshot: Payment update form

All changes were committed and pushed to the repository.
git add .
git commit -m "Added membership extension and payment tracking"
git push origin develop
Screenshot: Successful commit of changes

The membership extension and payment tracking functionality has been successfully implemented. Users can now extend their membership with a simple button click. Payment details, including amount, status, method, and transaction reference, are stored directly in the memberships table. The implemented solution ensures seamless tracking of membership renewals and payments.
This implementation improves user experience and administrative tracking by keeping all relevant payment data associated with the user's membership record.