Files
wticreatorstudio/Modules/Customer/Entities/UserCompany.php
T
Leonard Biano 0efe4f002c Customer Module Update
Company profile with additional contacts and customer notes
2024-07-04 19:20:44 +08:00

49 lines
1.4 KiB
PHP

<?php
namespace Modules\Customer\Entities;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use App\Models\User;
class UserCompany extends Model
{
protected $table = "user_company";
protected $guarded = ["id"];
public static function boot()
{
parent::boot();
static::updated(function ($model) {
if (auth()->user()->role->type == 'customer') {
$changes = $model->isDirty() ? $model->getDirty() : false;
if($changes){
$changes = \Arr::except($changes, ['updated_at']);
if(count($changes) > 0){
$updates = [];
foreach($changes as $attr => $value){
$old_value = $model->getOriginal($attr);
$new_value = $model->$attr;
$updates[] = "Updated ".str_replace('_', ' ', $attr)." from <b>". $old_value ."</b> to <b>". $new_value."</b>";
}
if(count($updates) > 0){
Cache::put(auth()->user()->id.'_company_info_updates', json_encode($updates), 60);
}
}
}
}
});
}
public function user(){
return $this->belongsTo(User::class, 'user_id', 'id');
}
}