In Part 6, we will start creating products section in admin panel. We will create products table with migration, will create route, products Controller and Model and then will make all products pages like add/edit and delete.
And also we will show all Categories in select drop down in Product Add/Edit form. So lets start creating products table first.
1) Create products table :-
First of all create products table with migration in the same way like we have created categories table.
So first run below command :-
php artisan make:migration create_products_table
Our migration file will be created.
See now in video, products migration file has been created. We will add all products columns now like id, category_id, product_name, product_code, product_color, description, price, image in products migration file.
See now in video, we have added all columns. For more details of column types and modifiers, follow our Laravel Migrations series at https://www.youtube.com/playlist?list=PLLUtELdNs2ZaIRraTsa5Li3iZKiXYMa2I
Now run below command :-
php artisan migrate
See now products table has been created with all required columns.
2) Create Controller
Now we will create ProductsController with below command :-
php artisan make:controller ProductsController
3) Create Model
Now create Products model with below command :-
php artisan make:model Product
4) Create Route :-
Now we will create route for Add Product in web.php file.
This route will have both GET/POST methods with add-product URL having addProduct function.
5) Create Function :-
Now we will create addProduct function in ProductsController.
6) Create add_product.blade.php file
First add "products" folder in "admin" folder under "views" folder and then create add_product.blade.php file.
See now add_product blade file is created. Now we will copy category blade file into this file and make changes in it. Actually purpose of copy is to get same design and form that we have for add category page as it will save our time.
Now we will add all products fields like Product Name, code, color etc. that we have added in producs table.
But first of all we will add category drop down as well so that we can select category for the product.
In Under Category select drop down, we will show all categories.
We will update addProduct function with categories variable that will contain all main and sub categories in select options.
Also don't forget to add headers in file first:
See now in video, Main Categories are coming in drop down. We will also show Sub Categories now in Main Categories.
Check now in video, all Categories with Sub Categories are displaying now. We are displaying Category names and their id's in values that we will pass and store as category_id in products table.
See now in video, our design of add product form is ready. We have added the Image upload field as well from form-common.html file of Matrix admin template and included uniform.css in admin_design.blade.php file. We are also showing now all categories with sub categories in Under Category drop down having category id's.
So in next video, we will post all these values in products table and then show them in view products page as well.
So stay tune for next video. And sorry for the mistakes.
Thanks for watching :)