#214

Опубликовано: 27 Декабрь 2024
на канале: Stack Developers
265
9

In Part-214 of the Laravel E-commerce series, we will start working on Exchange Order functionality like Amazon.

In this video, we will create an exchange_requests table with Migration and will add a few entries with Seeder commands.

We will also create a model for the exchange_requests table.

1) Create exchange_requests table:-
First of all, we will create an exchange_requests table with migration. Create migration file with name create_exchange_requests_table for creating exchange_requests table with below columns:-
id, order_id, user_id, product_size, required_size, product_code, exchange_reason, exchange_status, comment, created_at, updated_at

So, we will run the below artisan command to create a migration file for exchange_requests:-
php artisan make:migration create_exchange_requests_table

Open the create_exchange_requests_table migration file and add all required columns mentioned earlier.

Now, we will run below artisan command to create an exchange_requests table with required columns:-
php artisan migrate

2) Create ExchangeRequest model:-
Create an ExchangeRequest model by running the below command:-
php artisan make:model ExchangeRequest

Now, We will create a Seeding for exchange_requests table to insert dummy exchange requests.

3) Writing Seeder / Create ExchangeRequestTableSeeder file :-
Now, we will generate Seeder and create an ExchangeRequestTableSeeder file where we will add records for the exchange_requests table.

Run below artisan command to generate Seeder and create ExchangeRequestTableSeeder file:-
php artisan make:seeder ExchangeRequestTableSeeder

The above command will create ExchangeRequestTableSeeder.php file at \database\seeds\

Now open the ExchangeRequestTableSeeder file and add a query for adding dummy exchange requests.

4) Update DatabaseSeeder.php file:-
Now update DatabaseSeeder.php file located at database/seeds/ to add ExchangeRequestTableSeeder class as shown in video.

5) Run below commands:-
Now run the below commands that will finally insert records into the exchange_requests table.
composer dump-autoload (if required)
php artisan db:seed

In the next video, we will update the user order detail page to show the exchange link.

Thanks for watching :)

Join this channel to get access to complete code/support:
   / @stackdevelopers