Просмотр файла app/Http/Controllers/Admin/CacheController.php

Размер файла: 1.98Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Http\Controllers\Admin;
  6.  
  7. use Illuminate\Http\RedirectResponse;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Artisan;
  10. use Illuminate\View\View;
  11.  
  12. class CacheController extends AdminController
  13. {
  14. /**
  15. * Главная страница
  16. *
  17. * @param Request $request
  18. *
  19. * @return View
  20. */
  21. public function index(Request $request): View
  22. {
  23. $type = $request->input('type', 'files');
  24.  
  25. if ($type === 'images') {
  26. $files = glob(public_path('uploads/thumbnails/*.{gif,png,jpg,jpeg}'), GLOB_BRACE);
  27. $files = paginate($files, 20, compact('type'));
  28. } elseif ($type === 'views') {
  29. $files = glob(storage_path('framework/views/*.php'), GLOB_BRACE);
  30. $files = paginate($files, 20, compact('type'));
  31. } else {
  32. $files = glob(storage_path('framework/cache/data/*/*/*'));
  33. $files = paginate($files, 20, compact('type'));
  34. }
  35.  
  36. return view('admin/caches/index', compact('files', 'type'));
  37. }
  38.  
  39. /**
  40. * Очистка кеша
  41. *
  42. * @param Request $request
  43. *
  44. * @return RedirectResponse
  45. */
  46. public function clear(Request $request): RedirectResponse
  47. {
  48. $type = $request->input('type');
  49.  
  50. if ($request->input('_token') === csrf_token()) {
  51. switch ($type) {
  52. case 'images':
  53. Artisan::call('image:clear');
  54. break;
  55. case 'views':
  56. Artisan::call('view:clear');
  57. break;
  58. default:
  59. Artisan::call('cache:clear');
  60. Artisan::call('route:clear');
  61. Artisan::call('config:clear');
  62. }
  63.  
  64. setFlash('success', __('admin.caches.success_cleared'));
  65. } else {
  66. setFlash('danger', __('validator.token'));
  67. }
  68.  
  69. return redirect('admin/caches?type=' . $type);
  70. }
  71. }