mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-30 20:16:46 -04:00
49 lines
1.4 KiB
PHP
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');
|
|
}
|
|
}
|