TASKS 16: Email Notifications - RadLeoOFC/laravel-admin-panel GitHub Wiki

Project Report: Email Notifications and Membership Expiration Reminders

Objective

The objective of this task was to implement automated email notifications for users for events like membership creation, desk booking confirmation, or membership expiration. Additionally, a scheduled Artisan command was required to check for memberships ending soon and send reminder emails automatically.


1. Configuring Mail

Steps Taken:

  • Updated the .env file with Mailtrap SMTP credentials.
  • Ensured that the MAIL_FROM_ADDRESS was set correctly.

Screenshot: Mailtrap SMTP Configuration

Mailtrap SMTP Configuration


2. Creating the Mailable Class

Steps Taken:

  • Created the MembershipCreated Mailable class using:

php artisan make:mail MembershipCreated

  • Defined the email subject and template.

Screenshot: MembershipCreated.php Class

MembershipCreated.php Class


3. Sending Email on Membership Creation

Steps Taken:

  • Updated the MembershipController@store method to send an email after successfully saving a membership.

  • Used:

    Mail::to($membership->user->email)->send(new MembershipCreated($membership));
    

Screenshot: MembershipController.php

Method store in MembershipController

Screenshot: Membership creation message

Membership Creation Message


4. Implementing Membership Expiration Reminders

Steps Taken:

  • Created a new Artisan command:

php artisan make:command SendMembershipExpirationReminder

  • Implemented logic to fetch memberships expiring in 3 days and send emails.
  • Registered the command in the scheduler.

Screenshot: SendMembershipExpirationReminder.php

SendMembershipExpirationReminder.php code

Screenshot: Membership expiration reminder was sent

Membership expiration reminder


5. Resolving Timezone Issues

Steps Taken:

  • Changed the application timezone to Europe/Kyiv in config/app.php.
  • Cleared and cached the configuration:

php artisan config:clear

php artisan cache:clear

php artisan config:cache

  • Verified timezone alignment between Laravel and MySQL.

Screenshot: Laravel Timezone in Tinker

Laravel Timezone in Tinker

Screenshot: MySQL Timezone Check

MySQL Timezone Check


6. Pushing the Project to GitHub

Steps Taken:

  • Checked the repository status:

git status

  • Committed changes:

git add .

git commit -m "Implemented email notifications and membership expiration reminders"

  • Switched to the develop branch:

git checkout develop

  • Pushed changes to GitHub:

git push origin develop

Screenshot: Git Push Output

Git Push Output


Conclusion

  • Successfully implemented email notifications for membership creation and expiration reminders.
  • Resolved timezone discrepancies between Laravel and MySQL.
  • Pushed the project to GitHub in the develop branch.