#43 Laravel 11 / MongoDB E-commerce Tutorial | Products Images (I) | Create Collection in MongoDB

preview_player
Показать описание

This is Part 43 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 Products images module.

In this part, we will create a products_images collection with migration in MongoDB and will also add one product image in it with seeder though later on we will add a product image from the admin panel. We will also create model for products images.

Remove Demo Alert from Admin Panel:

1) Create products_images collection :-
Now, we will create a products_images collection with migration. Create migration file with name create_products_images_table for creating products_images table with below columns:-
id, product_id, image, image_sort, status, created_at and updated_at

So, we will run the below artisan command to create a model and migration file for products_images:-
php artisan make:model ProductsImage -m

Replace default class with MongoDB Class in ProductsImage model:-
use MongoDB\Laravel\Eloquent\Model as Model;

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

Now, we will run below artisan command to create a products_images collection:-
php artisan migrate

Now products_images collection has been created.

Now, We will create Seeding for products_images table to insert one test product image from seeder command.

2) Writing Seeder / Create ProductsImagesTableSeeder file :-
First of all, we will generate seeder and create ProductsImagesTableSeeder file from where we will add one product image for products_images table.

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

Now open ProductsImagesTableSeeder file and add record for product image.

4) Run below command :-
Now run the below command that will finally insert product into products_images table.
php artisan db:seed

In the next video, we will work on adding multiple products images in add/edit product form in 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
Рекомендации по теме
Комментарии
Автор

hello sir thank u for your useful videos, i want to ask u how u deal with the icloud storage and do u use an external storage if yes can we have a tutorial of how move folder from the mac to the external storage .

imanenejmaoui
Автор

Hi sir, I have a question. In my project, users have different roles based on their region. For example, a user might be an admin in Dubai, a manager in India, and a team lead in Saudi Arabia. How can I implement this functionality in Laravel?

shaheryar
Автор

Sir I mailed you about my project.. Raj

loggedpr