filmov
tv
Laravel 11 Tutorial with MongoDB #97 | Coupon Codes (I) | Create Collection | Show Coupons in Admin

Показать описание
This is Part 97 of the Laravel 11 Tutorial in which we are building the e-commerce website with Laravel as the front end and MongoDB as the back end. From this video, we will start working on coupon code functionality.
We are going to create advance coupon functionality and will add coupon options like below:-
Coupon Option:- Manual or Automatic
Coupon Code
Single, Multiple or All Categories
Single, Multiple or All Users
Coupon Type :- Single or Multiple
Amount Type :- Percentage or Fixed
Amount
Expiry Date
Enable/Disable
For coupon code functionality, we will work back on the admin panel again and make a coupon code module there to add/edit/delete, and view coupons.
In this part, we will create a coupons collection with Migration and add a few dummy coupons with Seeder. And will display those coupons in the admin panel with Active/Inactive status.
We will also create a controller and model for coupons.
1) Create coupons collection:-
First of all, we will create coupons collection with migration with the below columns:-
id, coupon_option, coupon_code, categories, users, coupon_type, amount_type, amount, expiry_date, status, created_at, updated_at
So, we will run below artisan command to create migration file & model for coupons :-
php artisan make:model Coupon -m
Replace default class with MongoDB Class in Coupon model:-
use MongoDB\Laravel\Eloquent\Model as Model;
Open the create_coupons_table migration file and add all required columns mentioned earlier.
Now, we will run the artisan command to create a coupons collection with required columns:-
php artisan migrate
2) Create CouponsController:-
Create CouponsController by running the below command:-
php artisan make:controller Admin/CouponController
Now, We will run seeder commands for the coupons table to insert a few dummy coupons.
3) Writing Seeder / Create CouponsTableSeeder file :-
First of all, we will generate seeder and create CouponsTableSeeder file where we will add records for coupons table.
Run below artisan command to generate Seeder and create CouponsTableSeeder file :-
php artisan make:seeder CouponsTableSeeder
Now open CouponsTableSeeder file and add query for adding coupons.
5) Run below command:-
Now run the below command that will finally insert records into the coupons table.
php artisan db:seed --class=CouponsTableSeeder
Now, we will display coupons in the admin panel and work on enable/disable and delete options.
6) Create Route:-
// Coupons
Route::get('coupons',[CouponController::class,'coupons']);
7) Include Coupon Model :-
Include Coupon model at top of CouponController
use App\Models\Coupon;
8) Create coupons function :-
Now we will work on Active/Inactive status for Coupon
10) Create Route :-
Route::post('update-coupon-status',[CouponController::class,'updateCouponStatus']);
11) Create updateCouponStatus function :-
Now create updateCouponStatus function in CouponsController to update the status of the coupon to active or inactive.
Now we are able to display coupons and update their status to Active/Inactive.
In the next video, we will start working on the "Add Coupon" functionality.
Thanks for watching :)
Popular Stack Developers Series that can help you:-
►Join this channel to get the complete source code of all series:
#laravel11 #mongodb #mongodbtutorial