How to generate SLUG in Laravel

Controller Code

<?php

namespace App\Http\Controllers\Category;
use Illuminate\Support\Str;

class CategoryController extends Controller
{

 public function GenarateSingleSlug()
    {
         $categorySlug = $this->GenarateSlug($Category);
         print_r($categorySlug); 
    }
        
}

Slug Function in Controller

1- Single String Return

    public function GenarateSlug($name='')
    {
 
        return Str::slug($name, '-');
    }
    
    

2- Array Slug Return

    public function GenarateSlugArray($name='')
    {
 
        $slug = [
            Str::slug('Abdul', '-'),
            Str::slug('Mohammad', '-')
            ];
        return $slug;
    }

Leave a Reply

Your email address will not be published.