filmov
tv
Laravel 11 MongoDB Tutorial #128: Manage Shipping Costs (I) | Display Country wise Shipping Charges

Показать описание
This is Part 128 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 shipping management in Laravel. We will calculate the shipping charges that we will add on the total amount of the order. We will give an option in admin to add shipping for all the countries.
There are 2 methods of adding shipping charges in the E-commerce website. One is the simple way of adding shipping charges for all the countries and one is the advance way of adding shipping charges for all the countries weightwise in which we will add weight for all the products and shipping will be added according to the weight and country both.
1) Country-wise Shipping Charges Module (without Weight)
2) Country/Product Weight-wise Shipping Charges Module
First we are going to work on simple process of adding shipping charges for all the countries from admin panel.
In this video, we will create shipping_charges table with migration and will import list of countries. We will also create ShippingCharge model.
1) Create shipping_charges table :-
First of all, we will create a shipping_charges collection with the below columns :-
country, rate, status, created_at and updated_at
So, we will run below artisan command to create migration file and model for shipping_charges :-
php artisan make:model ShippingCharge -m
Replace with MongoDB class at ShippingCharge model:
use MongoDB\Laravel\Eloquent\Model as Model;
Open create_shipping_charges_table migration file and add all required columns mentioned earlier.
Now, we will run the below artisan command to create a shipping_charges collection with the required columns:-
php artisan migrate
Now, the shipping_charges collection has been created with all the required columns.
2) Import Countries:-
Now we will import countries into shipping_charges collection after making the CSV file of countries with country, rate and status columns.
3) Create ShippingController Controller :-
Create ShippingController under Admin by running below artisan command :-
php artisan make:controller Admin/ShippingController
Add link for the shipping charges at left sidebar of the admin panel.
5) Create Route :-
// Shipping Charges
Route::get('shipping-charges',[ShippingController::class,'shippingCharges']);
6) Create shippingCharges function :-
7) Include Header Statements:-
Add the below statement at the top of your ShippingController file:-
use App\Models\ShippingCharge;
use App\Models\AdminsRole;
use Session;
use Auth;
Now we are going to work on active/in-active status for the shipping charges.
In the next part, we will work on update functionality for the shipping charges.
Popular Stack Developers Series that can help you:-
►Join this channel to get the complete source code of all series:
#laravel11 #mongodb #mongodbtutorial