TIP 52 / 100

Trait That You Want to Add to a Few Models to Call Their Boot() Method Automatically.

If you have a Trait that you want to add to a few Models to call their boot() method automatically, you can call Trait's method as boot[TraitName]

php
class Transaction extends  Model
{
    use MultiTenantModelTrait;
}
php
class Task extends  Model
{
    use MultiTenantModelTrait;
}
php
trait MultiTenantModelTrait
{
    // Name the method boot[TraitName].
    // Laravel calls it automatically when booting the model that uses the trait.
    public static function bootMultiTenantModelTrait()
    {
        static::creating(function ($model) {
            if (!$isAdmin) {
                $isAdmin->created_by_id = auth()->id();
            }
        })
    }
}