filmov
tv
Laravel 11 with MongoDB #103 | Laravel Checkout (I) | Multiple Delivery Address | Create Collection
Показать описание
This is Part 103 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. We will start working on the one-page checkout process.
We will work on below features in the checkout process:-
1. Multiple Delivery Addresses
2. Review Cart Items
3. Payment Methods
We will first work on multiple delivery addresses that we will integrate on the checkout page.
In this part, we will create a delivery_addresses collection with Migration and will add one delivery address with Seeding.
We will also create a model for delivery addresses.
1) Create delivery_addresses collection:-
First of all, we will create a delivery_addresses collection with the below columns:-
user_id, name, address, city, state, country, pincode, mobile, status, created_at, updated_at
So, we will run the below artisan command to create a migration file and model for delivery addresses:-
php artisan make:model DeliveryAddress -m
Replace default class with MongoDB Class in DeliveryAddress model:-
use MongoDB\Laravel\Eloquent\Model as Model;
Open the create_delivery_addresses_table migration file and add all required columns mentioned earlier.
Now, we will run the artisan command to create a delivery_addresses table with the required columns:-
php artisan migrate
Now, We will create a Seeding for delivery_addresses table to insert a dummy delivery address.
2) Writing Seeder / Create DeliveryAddressTableSeeder file :-
Now, we will generate seeder and create DeliveryAddressTableSeeder file where we will add dummy delivery address for delivery_addresses table.
Run below artisan command to generate Seeder and create DeliveryAddressTableSeeder file :-
php artisan make:seeder DeliveryAddressTableSeeder
Now open DeliveryAddressTableSeeder file and add query for adding delivery address.
4) Run below commands :-
Now run below command that will finally insert records into delivery_addresses table.
composer dump-autoload (if required)
php artisan db:seed --class=DeliveryAddressTableSeeder
If in case Target class [TableSeeder] does not exist error comes then follow below link to resolve :-
In next video, we will display delivery address in checkout page and will also work on add/edit delivery address functionality.
Popular Stack Developers Series that can help you:-
►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
#laravel11 #mongodb #mongodbtutorial