<?php

namespace App\Traits;

use App\Models\User;

trait CrudTrait
{

    /**
     * Handle global fiels like company_id or created_by
     */
    public static function boot()
    {
        parent::boot();

        static::saving(function ($table) {
            $table->created_by = auth('web')->id();
        });
    }
    /**
     * @return belongsTo
     */

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by')
            ->select('users.id', 'users.name');
    }
}
