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

Top Laravel Security Best Practices: How to Secure Your Web Application 🚀

Restoring Your Data in Xampp: A Step-by-Step Guide

Implement a real-time, interactive map