Файловый менеджер - Редактировать - /home/clickysoft/public_html/securebeans.clickysoft.net/app/Traits/Observable.php
Назад
<?php namespace App\Traits; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Auth; use App\Models\Log; trait Observable { // bootObservable() will be called on model instantiation automatically public static function bootObservable() { static::saved(function (Model $model) { // create or update? if( $model->wasRecentlyCreated ) { static::logChange( $model, 'CREATED' ); } else { if( !$model->getChanges() ) { return; } static::logChange( $model, 'UPDATED' ); } }); static::deleted(function (Model $model) { static::logChange( $model, 'DELETED' ); }); } public static function logChange( Model $model, string $action ) { $model_name = (new \ReflectionClass(static::class))->getShortName(); Log::create([ 'user_id' => Auth::check() ? Auth::user()->id : null, 'model' => $model_name, 'action' => $action, 'message' => static::logSubject($model), // 'models' => [ // 'new' => $action !== 'DELETED' ? $model->getAttributes() : null, // 'old' => $action !== 'CREATED' ? $model->getOriginal() : null, // 'changed' => $action === 'UPDATED' ? $model->getChanges() : null, // ] ]); } /** * String to describe the model being updated / deleted / created * Override this in the model class * @return string */ public static function logSubject(Model $model){ $data = json_encode($model); return $data; // return static::logImplodeAssoc($model->attributesToArray()); // return $model->attributesToArray(); } public static function logImplodeAssoc(array $attrs): string { $l = ''; foreach( $attrs as $k => $v ) { $l .= "{ $k => $v } "; } return $l; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка