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
pragati asked 2 weeks ago

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

<?php

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
Jyoti answered 2 weeks ago
Your Answer

17 + 17 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com