How to create slug

In php laravel


use Illuminate\Support\Str;


class Post extends Model

{

    protected $fillable = ['title', 'content', 'slug'];


    public static function boot() {

        parent::boot();

        static::creating(function ($post) {

            $post->slug = Str::slug($post->title);

        });

    }

}



https://chatgpt.com/share/679dae98-24e8-8001-b0d5-02f4b60cb8e3

Comments

Popular posts from this blog

How to Check for NVIDIA GPU and Set It Up in Ubuntu

Use the Google Custom Search JSON API to retrieve images

How to Remove a File or Folder from Git Without Losing It Locally