create slug in php laravel code example
Example 1: Str slug laravel
use Illuminate\Support\Str;
$slug = Str::slug('Laravel 5 Framework', '-');
Example 2: generate slug on create laravel
public static function boot()
{
parent::boot();
static::creating(function($activity) {
$slug = \Str::slug($news->title);
$count = static::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count();
$activity->slug = $count ? "{$slug}-{$count}" : $slug;
});
}
Activity::create(['title'=>'lorem ipsum']);
Example 3: laravel slug
php artisan vendor:publish --provider="Cviebrock\EloquentSluggable\ServiceProvider"