In this tutorial, we will see how to generate tags system in laravel application using rtconner/laravel-tagging composer package.

Given below is the full example for laravel tags system tutorial example.

Step 1 : Install Laravel Fresh App

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

Step 2 : Setup Database Configuration

open ".env" file and change the database name, username and password in the env file.


Step 3 : Install rtconner/laravel-tagging Composer Package

install "rtconner/laravel-tagging" composer package to add tags so run this command:

composer require composer require rtconner/laravel-tagging


'providers' => [


make public configuration and then run migration for tags so run the command given below:

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

Step 4 : Create posts table and model

create posts table in your database. Run this command:

php artisan make:modal Post -m

Now run this following code after completion of above code successfully 


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePostsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('posts', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()

Run following command:

php artisan migrate



namespace App;

use Illuminate\Database\Eloquent\Model;
use App\User;

class Post extends Model
    use \Conner\Tagging\Taggable;
    protected $fillable = ['title','tags','description'];

Step 5 : Add Route

create route for posts listing and create post


Route::get('posts', 'PostController@create');
Route::post('posts', 'PostController@store');

Step 6 : Create Controller



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post;

class PostController extends Controller
    public function create()
        $posts = Post::all();
        return view('posts',compact('posts'));    

    public function store(Request $request)
        $this->validate($request, [
            'title' => 'required',
            'description' => 'required',
            'tags' => 'required',

        $input = $request->all();
        $tags = explode(", ", $input['tags']);
        $post = Post::create($input);

        return back()->with('success','Post created successfully.');

Step 7 : Create View File

create posts.blade.php(resources/views/posts.blade.php) for layout and we will display all posts and create posts form,so put following code:


<html lang="en">
    <title>Laravel Tag System Tutorial Example</title>
    <link rel="stylesheet" href="" integrity="sha256-aAr2Zpq8MZ+YA/D6JtRD3xtrwpEz2IqOS+pWD/7XKIw=" crossorigin="anonymous" />
    <link rel="stylesheet" href="" integrity="sha512-xmGTNt20S0t62wHLmQec2DauG9T+owP9e6VU8GigI0anN7OXLip9i7IwEhelasml2osdxX71XcYm6BQunTQeQg==" crossorigin="anonymous" />
    <script src=""></script>
    <script src="" integrity="sha256-OFRAJNoaD8L3Br5lglV7VyLRf0itmoBzWUoM+Sji4/8=" crossorigin="anonymous"></script>
    <script src="" integrity="sha512-VvWznBcyBJK71YKEKDMpZ0pCVxjNuKwApp4zLF3ul+CiflQi6aIJR+aZCP/qWsoFBA28avL5T5HA+RE+zrGQYg==" crossorigin="anonymous"></script>
    <script src="" integrity="sha512-KT0oYlhnDf0XQfjuCS/QIw4sjTHdkefv8rOJY5HHdNEZ6AmOh1DW/ZdSqpipe+2AEXym5D0khNu95Mtmw9VNKg==" crossorigin="anonymous"></script>
    <style type="text/css">
            background-color: #17a2b8;

        .label {
            display: inline-block;
            padding: .25em .4em;
            font-size: 75%;
            font-weight: 700;
            line-height: 1;
            text-align: center;
            white-space: nowrap;
            vertical-align: baseline;
            border-radius: .25rem;
            transition: color .15s ease-in-out,background-color .15s ease-in-out,
            border-color .15s ease-in-out,box-shadow .15s ease-in-out;
    <div class="row mt-5 mb-5 mr-0">
        <div class="col-md-10 offset-1">
            <div class="card">
                <div class="card-header bg-info text-white">
                    <h4>Laravel Tag System Tutorial Example -</h4>
                <div class="card-body">
                        <div class="alert alert-success">
                            {{ Session::get('success') }}
                    <form method="POST" action="{{ route('') }}">
                        <div class="form-group">
                            <label>Title : <span class="text-danger">*</span></label>
                            <input type="text" name="title" class="form-control">
                            @if ($errors->has('title'))
                                <span class="text-danger">{{ $errors->first('title') }}</span>
                        <div class="form-group">
                            <label>Description : <span class="text-danger">*</span></label>
                            <textarea class="form-control" name="description"></textarea>
                            @if ($errors->has('description'))
                                <span class="text-danger">{{ $errors->first('description') }}</span>
                        <div class="form-group">
                            <label>Tags : <span class="text-danger">*</span></label>
                            <input type="text" data-role="tagsinput" name="tags" class="form-control tags">
                            @if ($errors->has('tags'))
                                <span class="text-danger">{{ $errors->first('tags') }}</span>
                        <div class="form-group">
                            <button class="btn btn-success store-data btn-sm">Save</button>
                        @foreach($posts as $post)
                            <div class="post-section">
                                <div class="post-title">
                                    <h4>{{ $post->title }}</h4>
                                <div class="post-description">
                                    <p style="margin-bottom: 5px !important;">{{ $post->description }}</p>
                                <div class="post-tags mb-4">
                                    <strong>Tags : </strong>
                                    @foreach($post->tags as $tag)
                                        <span class="badge badge-info">{{$tag->name}}</span>

Run this command for quick run:

php artisan serve

Run this URL on your browser:


you can get more information about "rtconner/laravel-tagging" package from here :


I hope this example helps you.