TASKS 09 : Membership Database Structure & Relationships - RadLeoOFC/laravel-admin-panel GitHub Wiki

TASKS 9: Membership Table Implementation Report

1. Project Setup and Database Configuration

1.1 Opening the Project

The terminal was used to navigate to the project directory and start the Laravel development server.

Screenshot 1: Terminal showing navigation to the project folder and server startup.

The terminal is launched with transition to the project manager

1.2 Checking Database Configuration

The .env file was checked to ensure the database credentials were correctly set.

Screenshot 2: .env file displaying the database settings.

Open .env file with database settings


2. Migration for the Memberships Table

A migration file for the memberships table was created and modified to include necessary columns and foreign keys.

2.1 Creating the Migration

The following command was executed in the terminal:

php artisan make:migration create_memberships_table --create=memberships

2.2 Modifying the Migration File

The migration file located in database/migrations/ was updated to define the schema.

Screenshot 3: Opened migration file with added schema and foreign key constraints.

 Open migration file with code


3. Creating the Membership Model

A model for the memberships table was created and configured with relationships.

3.1 Creating the Model

The following command was executed:

php artisan make:model Membership

3.2 Defining Relationships

The Membership.php file was updated with belongsTo relationships for User and Desk.

Screenshot 4: Opened Membership.php file with Eloquent relationships.

Membership.php file with relationship definitions


4. Updating User and Desk Models

4.1 Adding Relationship to User.php

The hasMany relationship was added to the User model.

Screenshot 5: User.php file with hasMany relationship added.

Edited User.php file with relationship definition

4.2 Adding Relationship to Desk.php

The hasMany relationship was also added to the Desk model.

Screenshot 6: Desk.php file with hasMany relationship added.

Edited Desk.php file with relationship definition


5. Running the Migration

The migration was executed using the following command:

php artisan migrate

Screenshot 7: Terminal showing successful migration execution.

Terminal with successful migration execution

5.1 Verifying the Table in phpMyAdmin

The memberships table was verified in the database via phpMyAdmin.

Screenshot 8: phpMyAdmin displaying the memberships table.

Memberships table in phpMyAdmin


6. Testing in Tinker

6.1 Creating a Membership Record

The following commands were executed in Tinker to create a new membership record:

$user = User::find(1);
$desk = Desk::find(1);
$membership = Membership::create([
    'user_id' => $user->id,
    'desk_id' => $desk->id,
    'start_date' => now(),
    'end_date' => now()->addMonth(),
    'membership_type' => 'monthly',
    'price' => 100.00
]);

Screenshot 9: Terminal showing a successful record creation in Tinker.

Created entry in Tinker

6.2 Verifying Relationships

The following commands were executed to check if relationships are properly working:

$user->memberships;
$desk->memberships;

Screenshot 10: Tinker output displaying related memberships.

The result of running queries in Tinker


7. Committing and Pushing Changes to GitHub

7.1 Adding Changes to Git

The changes were added to Git and committed with the following commands:

git add .

git commit -m "Added memberships table and Eloquent relationships"

git push origin main

Screenshot 11: Terminal showing successful Git push.

Terminal showing successful Git push


7.2 Verifying Commit on GitHub

The repository was checked to confirm the commit was successfully uploaded.

Screenshot 12: GitHub repository showing the commit.

GitHub repository showing the commit


8. Conclusion

The memberships table was successfully created, relationships were established, and data insertion was verified through Tinker. All changes were committed to GitHub.

This report documents the entire process with supporting screenshots for verification.