İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BaseModel extends Model
|
||||
{
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::deleting(function ($model) {
|
||||
try {
|
||||
Log::debug('Preparing to log deleted record', [
|
||||
'table_name' => $model->getTable(),
|
||||
'record_id' => $model->getKey(),
|
||||
'data' => $model->toArray()
|
||||
]);
|
||||
|
||||
// Kullanıcı bilgilerini al
|
||||
$user = Auth::user();
|
||||
|
||||
// Silinen veriyi kaydet
|
||||
DB::table('deleted_records')->insert([
|
||||
'table_name' => $model->getTable(),
|
||||
'record_id' => $model->getKey(),
|
||||
'deleted_data' => json_encode($model->toArray()),
|
||||
'deleted_by' => $user ? $user->id : null,
|
||||
'deleted_by_name' => $user ? $user->name : null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
Log::debug('Successfully logged deleted record', [
|
||||
'table_name' => $model->getTable(),
|
||||
'record_id' => $model->getKey()
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to log deleted record', [
|
||||
'error' => $e->getMessage(),
|
||||
'table_name' => $model->getTable(),
|
||||
'record_id' => $model->getKey()
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user