fix: resolve force-delete for tours in panel admin
This commit is contained in:
@@ -16,6 +16,7 @@ use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class TourController extends Controller
|
||||
{
|
||||
@@ -325,14 +326,41 @@ class TourController extends Controller
|
||||
->with('success', 'تور با موفقیت بازگردانی شد.');
|
||||
}
|
||||
|
||||
|
||||
public function forceDelete($id)
|
||||
{
|
||||
$tour = Tour::onlyTrashed()->findOrFail($id);
|
||||
$tour = Tour::onlyTrashed()
|
||||
->with('images.file')
|
||||
->findOrFail($id);
|
||||
|
||||
try {
|
||||
DB::transaction(function () use ($tour) {
|
||||
foreach ($tour->images as $image) {
|
||||
$file = $image->file;
|
||||
|
||||
if ($file) {
|
||||
|
||||
Storage::disk('public')->delete($file->path);
|
||||
|
||||
$file->delete();
|
||||
}
|
||||
|
||||
|
||||
$image->delete();
|
||||
}
|
||||
|
||||
|
||||
$tour->forceDelete();
|
||||
});
|
||||
|
||||
return redirect()
|
||||
->route('admin.tours.trash.index')
|
||||
->with('success', 'تور بهصورت دائمی حذف شد.');
|
||||
->with('success', 'تور و تمام تصاویر و فایلهای آن بهصورت دائمی حذف شدند.');
|
||||
} catch (\Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return back()
|
||||
->with('error', 'حذف دائمی تور انجام نشد.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user