Back to Browse

Laravel 13 Tutorial #4 – Build AI Powered E-commerce | Create Categories Table | Define Relation

529 views
Premiered Mar 31, 2026
16:34

🔗Laravel 13 AI-Powered E-commerce Series Complete Playlist: https://www.youtube.com/playlist?list=PLLUtELdNs2ZbKO7vAqkQN4fuCRnp3O-Dp In Part 4 of the Laravel 13 AI Powered E-commerce Website series, we will create the Categories table. Categories help organize products into different sections such as Electronics, Fashion, Books, etc. Our system will support 3 levels of categories: Example: Electronics → Mobile Phones → Android Phones To achieve this, we will implement a self-referencing relationship using parent_id, which means a category can belong to another category. In this part, we will: • Create Categories migration • Support hierarchical categories (up to 3 levels) • Add parent_id self-referencing relationship • Add index for better performance • Add optional level column (for hierarchy control) • Add SEO fields • Add category ordering • Run migration • Create Category Model • Add relationships (parent & children) • Add automatic slug generation • Add dummy data using Seeder (structured way) 🛠 Step 1: Create Categories Migration Run the following command: php artisan make:migration create_categories_table Laravel will create a migration file inside: database/migrations 🛠 Step 2: Define Categories Table Columns Open the migration file and update the up() method 🛠 Step 3: Run Migration php artisan migrate 🧱 Step 4: Create Category Model Run: php artisan make:model Category This will create: app/Models/Category.php 🧠 Step 5: Update Category Model Open: app/Models/Category.php Add: protected $fillable = [ 'parent_id', 'name', 'slug', 'description', 'image', 'level', 'position', 'status', 'meta_title', 'meta_description', 'meta_keywords', ]; 👉 Add relationships 👉 Add automatic slug generation 🌱 Step 6: Create Categories Seeder Run: php artisan make:Seeder CategorySeeder Open: database/seeders/CategorySeeder.php Add this at the top: use App\Models\Category; Update the run() method 🔗 Step 7: Register Seeder Open: database/seeders/DatabaseSeeder.php Add: CategorySeeder ▶ Step 8: Run Seeder php artisan db:seed --class=CategorySeeder Now dummy categories will be inserted. 💡 Real-World Tip: Large e-commerce websites use indexed and hierarchical categories for better performance and scalability. ✅ What We Completed in This Part ✔ Created categories table ✔ Added hierarchical categories support ✔ Added SEO fields ✔ Added category ordering ✔ Optimized performance using index ✔ Created Category model ✔ Added relationships ✔ Implemented slug automation ✔ Inserted dummy data using seeder Now categories are ready with real data. 🚀 In the Next Part In Part 5, we will: • Create the Products table • Add pricing and inventory • Add SEO fields • Connect products with categories • Insert dummy products using seeder 🔗Laravel 13 AI-Powered E-commerce Series Complete Playlist: https://www.youtube.com/playlist?list=PLLUtELdNs2ZbKO7vAqkQN4fuCRnp3O-Dp 📢 Don’t forget to Like, Share & Subscribe for more Laravel tutorials! 🚀 🔗Bookmark & follow this Laravel 13 AI-Powered E-commerce Series: https://www.youtube.com/playlist?list=PLLUtELdNs2ZbKO7vAqkQN4fuCRnp3O-Dp ►Click here to subscribe for Laravel & other updates - https://www.youtube.com/stackdevelopers Popular Stack Developers Series that can help you:- 🔗Laravel 12 Multi-Vendor E-commerce Series Complete Playlist: https://www.youtube.com/playlist?list=PLLUtELdNs2ZZ_hI7DvqrrhX-ASGD1U2Dl ►Laravel 12 Tutorial (with MySQL): https://www.youtube.com/playlist?list=PLLUtELdNs2ZbqkUOd-oXHemay3BrsqZqC ►Laravel 11 Tutorial (with MongoDB): https://www.youtube.com/playlist?list=PLLUtELdNs2ZYTn3ft4BMaAilhZJYLMs9d ►Laravel 11 PostgreSQL Tutorial: https://www.youtube.com/playlist?list=PLLUtELdNs2ZZy4jI-wu4jYUL7rbvC8Mgh ►Laravel API Tutorial - https://www.youtube.com/playlist?list=PLLUtELdNs2ZbcCsd4yAAiBU2L3ROREk8P ►jQuery Tutorial - https://www.youtube.com/playlist?list=PLLUtELdNs2ZbMYoUA46GIonOH29KcjtxA ►Laravel Basic E-commerce Series - https://www.youtube.com/playlist?list=PLLUtELdNs2ZY5drPxIWzpq5crhantlzp7 ►Laravel Dating Series - https://www.youtube.com/playlist?list=PLLUtELdNs2ZZrPUnxjlomErJfNvkyS6Hf ►Join this channel to get the complete source code of all series: https://www.youtube.com/channel/UCExO2i-tLU1NyVZD6zOJQlw/join Follow Stack Developers on Social Media to get updates and resolve your queries ►Like Facebook Page to get updates - http://facebook.com/stackdevelopers2/ ►Join Facebook Group to resolve your queries - http://facebook.com/groups/stackdevelopers ►Follow on Instagram - https://www.instagram.com/stackdevelopers2/ ►Follow on GitHub - https://github.com/stackdevelopers #Laravel13 #LaravelEcommerce #MultiVendor #EcommerceDevelopment #WebDevelopment #LaravelTutorial

Download

1 formats

Video Formats

360pmp421.7 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Laravel 13 Tutorial #4 – Build AI Powered E-commerce | Create Categories Table | Define Relation | NatokHD