filmov
tv
#45 Laravel 11 / MongoDB Tutorial | Products Attributes (I) | Create Collection | Insert Attributes
Показать описание
This is Part 45 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 Products attributes module.
In this part, we will create a products_attributes table with migration and will also add a few product attributes in it with Seeding though later on we will add product attributes from the admin panel.
We will also create a model for products attributes.
1) Create products_attributes collection:-
First of all, we will create products_attributes collection with migration having below columns:-
product_id, sku, size, price, stock and status
So, we will run the below artisan command to create a Model and migration file for products_attributes:-
php artisan make:model ProductsAttribute -m
Replace default class with MongoDB Class in ProductsAttribute model:-
use MongoDB\Laravel\Eloquent\Model as Model;
Now, open the create_products_attributes_table migration file and add all required columns mentioned earlier.
Now, we will run below artisan command to create a products_attributes table with the required columns:-
php artisan migrate
Now products_attributes table has been created with all the required columns.
Now, We will create a Seeder for the products_attributes table to insert one test product attribute from the file.
2) Writing Seeder / Create ProductsAttributesTableSeeder file:-
Now, we will generate a seeder and create a ProductsAttributesTableSeeder file from where we will add one product attribute for the products_attributes table.
Run the below artisan command to generate Seeder and create ProductsAttributesTableSeeder file:-
php artisan make:seeder ProductsAttributesTableSeeder
Now open the ProductsAttributesTableSeeder file and add record for product attribute.
4) Run below command:-
Now run the below command that will finally insert the product into the products_attributes table.
php artisan db:seed
In the next video, we will work on adding Product Attributes fields in the Add\Edit Product form in the admin panel.
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 #laravel11tutorial #mongodb
Комментарии