Try to search your question here, if you can't find : Ask Any Question Now ?

Laravel – How to call call function from trait boot

HomeCategory: stackoverflowLaravel – How to call call function from trait boot
Avatarpragati asked 3 months ago

I just create a Trait to generate slugs to my models:


namespace AppTraits;

trait SlugGenerator
    public function slugGenerator($slug = null)
        return $slug ?? 'UUIDGeneratorFunction';

    public static function bootSlugGenerator()
        static::creating(function ($model) {
            // How to call slugGenerator() function here?
            $model->slug = slugGenerator();

The question is: How to call the slugGenerator() function inside my trait boot?

And if I want to change the slug Generator from any model, the way I’m setting the $slug variable is right?

1 Answers
Best Answer
AvatarJyoti answered 3 months ago
Your Answer

12 + 9 =

Popular Tags

WP Facebook Auto Publish Powered By :