feat:add final changes
This commit is contained in:
@@ -119,7 +119,7 @@ class FlightController extends Controller
|
||||
'airports'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function edit(Flight $flight)
|
||||
{
|
||||
@@ -164,7 +164,6 @@ class FlightController extends Controller
|
||||
|
||||
try {
|
||||
|
||||
// 1. ذخیره عکس
|
||||
$image = $request->file('image');
|
||||
|
||||
$imageName = time()
|
||||
@@ -179,7 +178,6 @@ class FlightController extends Controller
|
||||
'public'
|
||||
);
|
||||
|
||||
// 2. ایجاد رکورد فایل
|
||||
$file = File::create([
|
||||
'name' => $imageName,
|
||||
'size' => $image->getSize(),
|
||||
@@ -188,7 +186,6 @@ class FlightController extends Controller
|
||||
'extension' => $image->extension(),
|
||||
]);
|
||||
|
||||
// 3. ایجاد پرواز با file_id
|
||||
$flight = Flight::create([
|
||||
'file_id' => $file->id,
|
||||
'arrival_aiport_id' => $request->arrival_aiport_id,
|
||||
@@ -204,6 +201,9 @@ class FlightController extends Controller
|
||||
'status' => $request->status,
|
||||
]);
|
||||
|
||||
// ثبت لاگ ایجاد پرواز
|
||||
logActivity($flight, 'created');
|
||||
|
||||
DB::commit();
|
||||
|
||||
} catch (Exception $exception) {
|
||||
@@ -232,7 +232,6 @@ class FlightController extends Controller
|
||||
|
||||
$oldFile = $flight->file;
|
||||
|
||||
// اطلاعات پرواز
|
||||
$flight->update([
|
||||
'arrival_aiport_id' => $request->arrival_aiport_id,
|
||||
'departure_airport_id' => $request->departure_airport_id,
|
||||
@@ -246,16 +245,16 @@ class FlightController extends Controller
|
||||
'status' => $request->status,
|
||||
]);
|
||||
|
||||
// ثبت لاگ ویرایش پرواز (باید بلافاصله بعد از update صدا زده شود)
|
||||
logActivity($flight, 'updated');
|
||||
|
||||
|
||||
// اگر عکس جدید انتخاب شده
|
||||
if ($request->hasFile('image')) {
|
||||
|
||||
$image = $request->file('image');
|
||||
|
||||
// ذخیره عکس جدید
|
||||
$path = $image->store('flights', 'public');
|
||||
|
||||
// ایجاد رکورد فایل جدید
|
||||
$newFile = File::create([
|
||||
'name' => pathinfo(
|
||||
$image->hashName(),
|
||||
@@ -267,15 +266,13 @@ class FlightController extends Controller
|
||||
'path' => $path,
|
||||
]);
|
||||
|
||||
// اتصال پرواز به فایل جدید
|
||||
$flight->update([
|
||||
'file_id' => $newFile->id,
|
||||
]);
|
||||
|
||||
// ثبت لاگ تغییر عکس (بهصورت جدا، چون update دومیه)
|
||||
logActivity($flight, 'updated');
|
||||
|
||||
// حذف فقط فایل فیزیکی قبلی
|
||||
// رکورد files قبلی را حذف نمیکنیم
|
||||
// چون FK روی flights.file_id وجود دارد.
|
||||
if ($oldFile) {
|
||||
|
||||
if (Storage::disk('public')->exists($oldFile->path)) {
|
||||
@@ -324,15 +321,5 @@ class FlightController extends Controller
|
||||
->with('success', 'پرواز با موفقیت حذف شد.');
|
||||
}
|
||||
|
||||
public function logs(Flight $flight)
|
||||
{
|
||||
$logs = ActivityLog::query()
|
||||
->where('model_type', Flight::class)
|
||||
->where('model_id', $flight->id)
|
||||
->with('admin')
|
||||
->orderByDesc('created_at')
|
||||
->paginate(20);
|
||||
|
||||
return view('admin.flights.logs', compact('flight', 'logs'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user