►Laravel 11 Tutorial (with MongoDB):
This is Part 108 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 part, we will start working on the order placement process.
For placing orders either from COD or Paypal, we need to create orders tables to insert the orders details into them so that admin and user can view orders details anytime they want.
So in this video, we are going to create the below 2 collections with Migration on MongoDB:-
1) orders collection
2) orders_products collection
We will also create model for orders and orders_products tables.
First of all, we will add one condition to check if there are cart items before proceed further to checkout and order placement.
1) Update checkout function :-
We will add condition to check the cart items. If cart items are empty we will redirect the customer back to cart page from checkout.
2) Create orders collection :-
Now, we will create orders collection with migration. "orders" table will contain delivery details, coupon / shipping details, grand total and other main information.
We will create orders collection with below columns and data types:-
So, we will run the below artisan command to create a model and migration file for the orders collection:-
php artisan make:model Order -m
Replace default class with MongoDB Class in DeliveryAddress model:-
use MongoDB\Laravel\Eloquent\Model as Model;
Open the create_orders_table migration file and add all required columns mentioned earlier.
Now, we will run below artisan command to create orders table with required columns :-
php artisan migrate
3) Create orders_products collection :-
Now create an orders_products collection that will have ordered products data that the user going to order.
Create orders_products collection with below columns and data types:-
order_id int(11)
user_id int(11)
product_id int(11)
product_code varchar(255)
product_name varchar(255)
product_color varchar(255)
product_size varchar(255)
product_sku varchar(255)
product_price float
product_qty int(11)
created_at datetime
updated_at timestamp
So, we will run the below artisan command to create model and migration file for orders_products table together:-
php artisan make:model OrdersProduct -m
Replace default class with MongoDB Class in DeliveryAddress model:-
use MongoDB\Laravel\Eloquent\Model as Model;
Open the create_orders_products_table migration file and add all required columns mentioned earlier.
Now, we will run below artisan command to create orders_products table with required columns :-
php artisan migrate
Now our orders tables are ready.
In the next part, we will place order and insert order details in the orders and orders_products tables.
►Click here to subscribe for Laravel & other updates -
Popular Stack Developers Series that can help you:-
►Laravel 11 PostgreSQL Tutorial:
►Laravel 10 Tutorial:
►Laravel Multi-Vendor E-commerce Series -
►React JS Tutorial for Beginners with Laravel -
►Laravel Tutorial for Beginners -
►GIT Tutorial for Beginners -
►Laravel API Tutorial -
►Laravel Interview Questions -
►jQuery Tutorial -
►Laravel Basic E-commerce Series -
►Laravel Dating Series -
►Join this channel to get the complete source code of all series:
Follow Stack Developers on Social Media to get updates and resolve your queries
►Like Facebook Page to get updates -
►Join Facebook Group to resolve your queries -
►Follow on Instagram -
►Follow on GitHub -