57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ActivityLog;
|
|
use App\Models\Flight;
|
|
use App\Models\Tour;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ActivityLogController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$logs = ActivityLog::query()
|
|
->whereIn('model_type', [Tour::class, Flight::class])
|
|
->with('admin')
|
|
->when($request->filled('model_type'), function ($query) use ($request) {
|
|
|
|
$query->where('model_type', $request->input('model_type'));
|
|
|
|
})
|
|
->when($request->filled('action'), function ($query) use ($request) {
|
|
|
|
$query->where('action', $request->input('action'));
|
|
|
|
})
|
|
->orderByDesc('created_at')
|
|
->paginate(20)
|
|
->withQueryString()
|
|
->through(function ($log) {
|
|
|
|
$modelClass = $log->model_type;
|
|
|
|
$relatedModel = $modelClass::find($log->model_id);
|
|
|
|
$log->model_title = $relatedModel->title ?? '(حذف شده)';
|
|
|
|
$log->model_label = $log->model_type === Tour::class
|
|
? 'تور'
|
|
: 'پرواز';
|
|
|
|
$log->model_edit_route = null;
|
|
|
|
if ($relatedModel) {
|
|
$log->model_edit_route = $log->model_type === Tour::class
|
|
? route('admin.tours.edit', $log->model_id)
|
|
: route('admin.flights.edit', $log->model_id);
|
|
}
|
|
|
|
return $log;
|
|
});
|
|
|
|
return view('admin.activity-logs.index', compact('logs'));
|
|
}
|
|
}
|