Laravel 7/6 Generate Unique Slug Example

In this tutorial you will learn about the Laravel 7/6 Generate Unique Slug Example and its application with practical example.

In this Laravel 7/6 Generate Unique Slug Example I will show you how to generate unique slug for blog posts title in laravel application. In this tutorial you will learn to generate unique slug for post title. In this example I will demonstrate you to generate unique slug or seo friendly slug url for post title. We will be using cviebrock eloquent sluggable laravel package for generating seo friendly url in laravel.

Laravel 7/6 Generate Unique Slug Example

  • Install Laravel Fresh New Setup
  • Setup Database Credentials
  • Install Eloquent Sluggable Package
  • Generate Model and Migration
  • Create Resource Route & Controller
  • Create the blade view
  • Start Development Server
  • Conclusion

1). Install Laravel Fresh New Setup

First of all we need to create a fresh laravel project, download and install Laravel using the below command

2. Setup Database Credentials

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

3. Install Eloquent Sluggable Package

In this step, we will install Eloquent Sluggable Package via the composer dependency manager. Use the following command to install Eloquent Sluggable Package.

After installing eloquent sluggable package, run the following command:

4. Generate Model and Migration

Now, in this step we will create model and migration file. Please run the following command:

The above command will create a model name Post and also create a migration file for the post table. Now put the following code in it:

Now, in this step we will create model and migration file. Please run the following command:

If you found any query builder error in command prompt go to => app\Providers\AppServiceProvider.php and put the below code here :

And then run this below command :

Now, add the fillable property inside Post.php file as following:

5. Create Resource Route & Controller

In this step we will create a resource route and controller using following command:

now, we have to add the resource route. Go to routes/web.php put the below routes here :

Now, go to app/HTTP/Controller/PostController and put the below code here :

6. Create the blade view

Now we will create following blade files:

  • List.blade.php
  • Create.blade.php

List.blade.php

Create.blade.php

7. Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 7/6 Generate Unique Slug Example and its application with practical example. I hope you will like this tutorial.