git add .

git commit "feat: implement activity logging for tours and flights"
This commit is contained in:
2026-08-19 14:59:26 +03:30
parent 7cf68cc02f
commit 4d8839e802
9 changed files with 326 additions and 3 deletions
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\ActivityLog;
use Illuminate\Http\Request;
class ActivityLogController extends Controller
{
//
public function index()
{
$logs=ActivityLog::with('admin')
->latest()
->paginate(4);
return view('admin.activityLog.index',compact('logs'));
}
}
@@ -20,8 +20,16 @@ class DashboardController extends Controller
$flightsCount = Flight::count();
$tourViews= Tour::query()
->selectRaw('DATE(create_at) as date,SUM(views) as total')
->where('created_at','>=',now()->subDays(9))
->qroupBy('date')
->orderBy('date')
->get();
return view('admin.dashboard',compact('adminsCount',
'usersCount','toursCount','flightsCount'
'usersCount','toursCount','flightsCount','tourViews'
));
}
}
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\FlightStoreRequest;
use App\Models\ActivityLog;
use App\Models\Flight;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@@ -48,8 +49,15 @@ class FlightController extends Controller
$data['created_by'] = auth('admin')->id();
Flight::create($data);
$flight = Flight::create($data);
ActivityLog::create([
'admin_id' => auth('admin')->id(),
'action' => 'create',
'model' => 'Flight',
'model_id' => $flight->id,
'description' => 'ثبت پرواز جدید',
]);
DB::commit();
@@ -107,6 +115,13 @@ class FlightController extends Controller
$flight->update($data);
ActivityLog::create([
'admin_id' => auth('admin')->id(),
'action' => 'update',
'model' => 'Flight',
'model_id' => $flight->id,
'description' => 'ویرایش اطلاعات پرواز',
]);
DB::commit();
@@ -136,6 +151,13 @@ class FlightController extends Controller
}
ActivityLog::create([
'admin_id' => auth('admin')->id(),
'action' => 'delete',
'model' => 'Flight',
'model_id' => $flight->id,
'description' => 'حذف پرواز',
]);
$flight->delete();
+26 -1
View File
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\TourStoreRequest;
use App\Models\ActivityLog;
use App\Models\Tour;
use App\Models\TravelType;
use Illuminate\Http\Request;
@@ -50,7 +51,15 @@ class TourController extends Controller
$data['created_by'] = auth('admin')->id();
Tour::create($data);
$tour = Tour::create($data);
ActivityLog::create([
'admin_id' => auth('admin')->id(),
'action' => 'create',
'model' => 'Tour',
'model_id' => $tour->id,
'description' => 'ثبت تور جدید',
]);
DB::commit();
@@ -109,6 +118,14 @@ class TourController extends Controller
$tour->update($data);
ActivityLog::create([
'admin_id' => auth('admin')->id(),
'action' => 'create',
'model' => 'Tour',
'model_id' => $tour->id,
'description' => 'ویرایش تور',
]);
DB::commit();
@@ -138,6 +155,14 @@ class TourController extends Controller
}
ActivityLog::create([
'admin_id' => auth('admin')->id(),
'action' => 'create',
'model' => 'Tour',
'model_id' => $tour->id,
'description' => 'حذف تور',
]);
$tour->delete();
+49
View File
@@ -0,0 +1,49 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class ActivityLog
*
* @property int $id
* @property int|null $admin_id
* @property string $action
* @property string $model
* @property int $model_id
* @property string|null $description
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @package App\Models
*/
class ActivityLog extends Model
{
protected $table = 'activity_logs';
public static $snakeAttributes = false;
protected $casts = [
'admin_id' => 'int',
'model_id' => 'int'
];
protected $fillable = [
'admin_id',
'action',
'model',
'model_id',
'description'
];
public function admin()
{
return $this->belongsTo(Admin::class);
}
}
+4
View File
@@ -103,4 +103,8 @@ class Admin extends User
})
->exists();
}
public function activityLogs()
{
return $this->hasMany(ActivityLog::class);
}
}
@@ -0,0 +1,182 @@
@extends('admin.layouts.app')
@section('breadcrumb')
<span>
گزارش فعالیت‌ها
</span>
@endsection
@section('content')
<div class="container mt-4">
<div class="card shadow">
<div class="card-body">
<h5 class="mb-4">
گزارش تغییرات سیستم
</h5>
<div class="table-responsive">
<table class="table table-bordered text-center align-middle">
<thead class="table-light">
<tr>
<th>
شناسه
</th>
<th>
کاربر
</th>
<th>
عملیات
</th>
<th>
بخش
</th>
<th>
شناسه مورد
</th>
<th>
توضیحات
</th>
<th>
تاریخ
</th>
</tr>
</thead>
<tbody>
@forelse($logs as $log)
<tr>
<td>
{{ $loop->iteration }}
</td>
<td>
{{ $log->admin->name ?? '-' }}
</td>
<td>
@switch($log->action)
@case('create')
<span class="badge bg-success">
ایجاد
</span>
@break
@case('update')
<span class="badge bg-warning">
ویرایش
</span>
@break
@case('delete')
<span class="badge bg-danger">
حذف
</span>
@break
@default
{{ $log->action }}
@endswitch
</td>
<td>
@if($log->model == 'Flight')
پرواز
@elseif($log->model == 'Tour')
تور
@else
{{ $log->model }}
@endif
</td>
<td>
{{ $log->model_id }}
</td>
<td>
{{ $log->description }}
</td>
<td>
{{ $log->created_at->toJalali()->format('Y/m/d H:i') }}
</td>
</tr>
@empty
<tr>
<td colspan="7">
موردی یافت نشد
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
{{ $logs->links() }}
</div>
</div>
</div>
@endsection
@@ -70,6 +70,16 @@
</li>
<li class="nav-item mb-2">
<a href="{{ route('admin.activity-logs.index') }}"
class="nav-link text-white">
گزارش فعالیت ها
</a>
</li>
+3
View File
@@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\Admin\ActivityLogController;
use App\Http\Controllers\Admin\AdminController;
use App\Http\Controllers\Admin\Auth\AuthController;
use App\Http\Controllers\Admin\Auth\DashboardController;
@@ -102,6 +103,8 @@ Route::prefix('admin')->name('admin.')->group(function (){
Route::put('permissions', 'updatePermissions')->name('permissions.update');
});
});
Route::get('/activity-logs', [ActivityLogController::class, 'index'])
->name('activity-logs.index');
});
});