Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Laravel 8 Dynamic Bootstrap Tabs Example Tutorial

Laravel 8 Dynamic Bootstrap Tabs Example Tutorial

Posted on October 15, 2020September 26, 2021 By XpertPhp

Today we are telling you how to make Dynamic Bootstrap Tabs Example in laravel 8. if you want to learn dynamic bootstrap tabs in laravel then you can follow our tutorial.

Sometimes, we see a tabs system on many e-commerce websites. we have given a simple example of how can make it in laravel. so you can follow the below example.

Overview

Step 1: Install Laravel 8

Step 2: Setting Database Configuration

Step 3: Create Table using migration

Step 4: Create Route

Step 5: Create a Model and Controller

Step 6: Create View File

Step 7: Run Our Laravel Application

Step 1: Install Laravel 8

We are going to install laravel 8, so first open the command prompt or terminal and go to xampp htdocs folder directory using the command prompt. after then run the below command for laravel 8 install.

PHP
1
composer create-project --prefer-dist laravel/laravel laravel8_bootstrap_tabs

Step 2: Setting Database Configuration

After the complete installation of laravel. we have to database configuration. now we will open the .env file and change the database name, username, password in the .env file. See below changes in a .env file.

PHP
1
2
3
4
5
6
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Enter_Your_Database_Name(laravel8_bootstrap_tabs)
DB_USERNAME=Enter_Your_Database_Username(root)
DB_PASSWORD=Enter_Your_Database_Password(root)

Step 3: Create Table using migration

Now, We need to create a migration. so we will below command using create the products and categories tables.

PHP
1
2
php artisan make:migration create_products_table --create=products
php artisan make:migration create_categories_table --create=categories

After complete migration. we need the below changes in the database/migrations/create_products_table.php and database/migrations/create_categories_table.php files.
database/migrations/create_products_table.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
 
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
 
class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->foreignId('category_id');
            $table->string('name');
            $table->timestamps();
        });
    }
 
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}
?>

database/migrations/create_categories_table.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
 
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
 
class CreateCategoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
         Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });
    }
 
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('categories');
    }
}
?>

Run the below command. after the changes above file.

PHP
1
php artisan migrate

Step 4: Create Route

We have to need put below student resource route in routes/web.php

PHP
1
2
3
4
5
Route::namespace('App\Http\Controllers')->middleware('guest')->group(function () {
  
    Route::get('/', '[email protected]');
  
});

Step 5: Create a Model and Controller

Here below command help to create the controller and model.

PHP
1
2
3
php artisan make:controller ProductController
php artisan make:model Product
php artisan make:model Category

app/Models/Product.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
namespace App\Models;
 
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
 
class Product extends Model
{
    use HasFactory;
 
    public function products()
    {
     return $this->belongsTo(Category::class);
    }
}

app/Models/Category.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
namespace App\Models;
 
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
 
class Category extends Model
{
    use HasFactory;
 
    public function products()
    {
     return $this->hasMany(Product::class);
    }
}

ProductController.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
namespace App\Http\Controllers;
use App\Models\Category;
use Illuminate\Http\Request;
 
class ProductController extends Controller
{
    public function index()
    {  
        $category = Category::with('products')->get();
     return view()->exists('welcome') ? view('welcome',compact('category')) : '';
    }
}

Step 6: Create View File

So finally, first we need to update the welcome.blade.php file in the “resources/ views/” directory.

welcome.blade.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel 8 Dynamic Bootstrap Tabs Example Tutorial - XpertPhp</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    </head>
    <body>
 
    <div role="tabpanel">
      <ul class="nav nav-tabs" role="tablist">
          @foreach ($category as $item)
            <li role="presentation" class="{{ $item->id == 1 ? 'active' : '' }}">
              <a href="#home{{ $item->id }}" aria-controls="home" role="tab" data-toggle="tab">{{ $item->name }}</a>
            </li>
          @endforeach
      </ul>
      <div class="tab-content">
       @foreach ($category as $item)
            <div role="tabpanel" class="tab-pane {{ $item->id == 1 ? 'active' : '' }}" id="home{{ $item->id }}" class="active">
              <ul>
                @foreach ($item->products as $element)
                   <li>{{ $element->name}}</li>
                @endforeach
              </ul>
            </div>
       @endforeach
      </div>
    </div>
 
    </body>
</html>

Step 7: Run Our Laravel Application
We can start the server and run this example using the below command.

1
php artisan serve

Now we will run our example using the below Url in the browser.

1
http://127.0.0.1:8000/

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Recommended Posts:

  • Laravel many to many eloquent relationship tutorial example
  • Laravel 8 Vue JS Infinite Scroll Load More Example
  • Laravel 8 Chart Js Example From Scratch
  • laravel eloquent Limit And Offset query example
  • Laravel 8 Get Current URL With Parameters
Laravel Tags:Laravel 8, laravel 8 example

Post navigation

Previous Post: Angular 10 Multiple File Upload Example Tutorial
Next Post: Laravel 8 Highcharts Example From Scratch

Latest Posts

  • How to Convert Date and Time from one timezone to another in php
  • how to get current date and time in php
  • Drag and Drop Reorder Items with jQuery, PHP & MySQL
  • Laravel 9 Toastr Notifications Example Tutorial
  • Laravel 9 CRUD Operation Example Using Google Firebase
  • Laravel 9 CKeditor Image Upload With Example
  • Laravel 9 Summernote Image Upload With Example
  • Laravel 9 Stripe Payment Gateway Integrate Example
  • How To Send Email Using Mailtrap In Laravel 9
  • Laravel 9 Fullcalendar Ajax Example Tutorial

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Age Calculator Online
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tricks jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch Laravel Socialite laravel social login nodejs pagination payment gateway php with mysql react js tutorial rewrite rule send mail validation wysiwyg editor

Copyright © 2018 - 2022,

All Rights Reserved Powered by XpertPhp.com