Laravel Str slug() Function Example

In this example, I explain laravel Str slug() function. Laravel Str slug() function generates a URL friendly slug from the given string. We will show how to use Str slug() function in laravel.

Example : Laravel Str::slug() Function

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\Support\Str;

class UserController extends Controller
{
    public function index(){

        $slug = Str::slug('Laravel 5 Framework', '-');
        echo $slug;
        // laravel-5-framework
     }
}

routes/web.php

<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

Route::get('users', [UserController::class,'index']);

I hope you understand laravel Str slug() function and it can help you…

Read Also :  Laravel 8 One to Many Eloquent Relationship Tutorial