Tuesday, March 8, 2022

Create dynamic categories and subcategories in Laravel 7/8

 https://blog.codehunger.in/create-dynamic-categories-and-subcategories-in-laravel-7-8/

In this post, we will see how we can create categories and subcategories dynamically in laravel.

Run the command below to create the Category model and migration.

PHP

It will create the Category.php in app directory and date_str_create_categories_table.php in database/migrations directory.

Replace the code in date_str_create_categories_table.php file with the code below.

PHP

Replace the code of Category.php with the code below.

PHP

Add the line below to web.php

PHP

Run the command below to create the controller. It will create CategoryController.php in app/Http/Controllers directory.

PHP

Replace the CategoryController.php with the code below.

PHP

Now we are going to create the view files.

Create the file master.blade.php in resources/views/layouts directory and add the code below.

HTML

Create the file index.blade.php in resources/views/categories directory and copy the below code.

HTML

Create the file create.blade.php in resources/views/categories directory and add the code below.

HTML

Create the file edit.blade.php in resources/views/categories directory and add the code below.

HTML

Run command php artisan serve and run the url http://127.0.0.1:8000/categories in browser.

I hope it will helps you, if you have any query feel free to comment below.

No comments:

Post a Comment