How To Bootstrap Tags System In Laravel 8?




How To Bootstrap Tags System In Laravel 8?

Hi Friends,

This example is how to bootstrap tags system in laravel 8?.

This example is short code and easy way to understand in users.

You will learn how to create a tag system in the Laravel 8 application using the laravel-tagging package.

So let's start following step.

Step 1 - Download New Freash Laravel Application

composer create-project --prefer-dist laravel/laravel laravel-tag-blog

Move into the project’s root.

cd laravel-tag-blog

Step 2 - Add Database Details

The database is connected to the app by adding database details into the .env configuration files.







Step 3 - Install Laravel Tagging Package

Next, open the terminal add the command to install the laravel tagging package; this package offers the tag support for Laravel Eloquent models recklessly.

composer require rtconner/laravel-tagging

Step 4 - Add Tagging Service in Laravel




'providers' => [







Step 5 - Publish Tagging Service in Laravel

below command to publish in laravel.

php artisan vendor:publish --provider="Conner\Tagging\Providers\TaggingServiceProvider"

Next, you have to run a command to run the migration for the tags system, and it will generate tagging tables into the database.

php artisan migrate

Step 6 - Create Model and Migration

php artisan make:model TagPost -m

Update code in app/Models/Post.php file.


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Database\Eloquent\Model;

class TagPost extends Model


use HasFactory;

use \Conner\Tagging\Taggable;

protected $fillable = [





Now, get into the app/database/migrations/create_posts_table.php, and you have to insert the table values into this migration file.


use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

class CreateTagPostsTable extends Migration



* Run the migrations.


* @return void


public function up()


Schema::create('tag_posts', function (Blueprint $table) {








* Reverse the migrations.


* @return void


public function down()





Consequently, you have to execute a command to run migrations.

php artisan migrate

Step 7 - Set Up Controller

Let’s generate a new controller with the help of the following command.

php artisan make:controller TagController



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\TagPost;

class TagController extends Controller


public function index()


$tags = TagPost::all();

return view('tag',compact('tags'));


public function store(Request $request)


$this->validate($request, [

'title_name' => 'required',

'content' => 'required',

'tags' => 'required',


$input = $request->all();

$tags = explode(",", $request->tags);

$post = TagPost::create($input);


return back()->with('success','Tags added to database.');



Step 8 - Create Route



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\TagController;



| Web Routes



| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!



Route::get('/show-tags', [TagController::class, 'index']);

Route::post('/create-tags', [TagController::class, 'store']);

Step 9 - Create Blade File


<!DOCTYPE html>

<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">


<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Laravel 8 Tags System Example -</title>

<link href="" rel="stylesheet">

<link href="" rel="stylesheet" />


.bootstrap-tagsinput .tag{

margin-right: 2px;

color: #ffffff;

background: #2196f3;

padding: 3px 7px;

border-radius: 3px;


.bootstrap-tagsinput {

width: 100%;





<div class="container mt-5">

<h3 class="text-center mb-5">Laravel 8 Tags System Example -</h3>

<div class="row justify-content-center">

<div class="col-md-8">


<div class="alert alert-success">

{{ Session::get('success') }}






<form action="{{ url('create-tags') }}" method="POST">

{{ csrf_field() }}

<div class="mb-3">

<input type="text" class="form-control" name="title_name" placeholder="Enter title">

@if ($errors->has('title_name'))

<span class="text-danger">{{ $errors->first('<title></title>') }}</span>



<div class="mb-3">

<textarea class="form-control" name="content" placeholder="Enter content"></textarea>

@if ($errors->has('content'))

<span class="text-danger">{{ $errors->first('content') }}</span>



<div class="mb-3">

<input class="form-control" type="text" data-role="tagsinput" name="tags">

@if ($errors->has('tags'))

<span class="text-danger">{{ $errors->first('tags') }}</span>



<div class="d-grid">

<button class="btn btn-info btn-submit text-white">Submit</button>



<div class="alert alert-success p-1 mt-3 text-center">

Tag Collection



@foreach($tags as $key => $tag)

<h3><strong>Title</strong> : {{ $tag->title_name }}</h3>

<p><strong>Content :</strong> {{ $tag->content }}</p>



@foreach($tag->tags as $tag)

<label class="badge bg-primary">{{ $tag->name }}</label>








<script src=""></script>

<script src=""></script>



Step 10 - Run Laravel App

You need to run the laravel app follow command.

php artisan serve

Open your browser and use the url.



I hope it can help you......

#Laravel 8