File tree Expand file tree Collapse file tree
resources/js/components/admin Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77use App \Models \Resource ;
88use App \Models \Subject ;
99use App \Models \User ;
10+ use Illuminate \Support \Facades \Cache ;
1011use Inertia \Inertia ;
1112
1213class SubjectController extends Controller
1314{
1415 public function index ()
1516 {
16- $ subjects = Subject :: orderBy ( ' sort_order ' , ' asc ' )-> withCount ( ' nodes ' )-> get ();
17- $ notice = Notice :: activeForDisplay ();
17+ $ homeData = Cache :: rememberForever ( " home_page_data " , function () {
18+ $ subjects = Subject :: orderBy ( ' sort_order ' , ' asc ' )-> withCount ( ' nodes ' )-> get ();
1819
19- return Inertia ::render ('Home ' , [
20- 'subjects ' => $ subjects ,
21- 'subjectCount ' => $ subjects ->count (),
22- 'resourceCount ' => Resource ::count (),
23- 'contributorCount ' => User ::count (),
24- 'notice ' => $ notice ,
25- ]);
20+ return [
21+ 'subjects ' => $ subjects ->toArray (),
22+ 'subjectCount ' => $ subjects ->count (),
23+ 'resourceCount ' => Resource ::count (),
24+ 'contributorCount ' => User ::count (),
25+ 'notice ' => Notice ::activeForDisplay (),
26+ ];
27+ });
28+
29+ return Inertia ::render ('Home ' , $ homeData );
2630 }
2731
2832 public function show (Subject $ subject )
Original file line number Diff line number Diff line change 11<script setup lang="ts">
22import { Link , router } from ' @inertiajs/vue3' ;
3- import { LogOut } from ' lucide-vue-next' ;
3+ import { Database , LogOut } from ' lucide-vue-next' ;
44defineProps ({
55 navigation: Array ,
66});
@@ -9,6 +9,12 @@ const handleLogout = () => {
99 router .post (' /logout' );
1010 }
1111};
12+
13+ const handleClearCache = () => {
14+ if (confirm (' Are you sure you want to clear all cache?' )) {
15+ router .post (' /admin/clear-cache' );
16+ }
17+ };
1218 </script >
1319
1420<template >
@@ -50,6 +56,23 @@ const handleLogout = () => {
5056 </nav >
5157
5258 <div class =" space-y-3" >
59+ <button
60+ @click =" handleClearCache"
61+ class =" group relative flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-sm font-medium text-rose-600 transition-all duration-300 hover:bg-rose-50/60 hover:text-rose-700"
62+ >
63+ <span
64+ class =" absolute top-1/4 bottom-1/4 left-0 w-[3px] origin-center scale-y-0 rounded-full bg-rose-600 transition-transform duration-200 group-hover:scale-y-100"
65+ ></span >
66+ <Database
67+ class="h-4 w-4 text-rose-400 transition-all duration-300 ease-out group-hover:scale-110 group-hover:-rotate- [4deg] group-hover:text-rose-500 "
68+ :stroke-width =" 2 "
69+ />
70+ <span
71+ class =" transform transition-transform duration-300 ease-out group-hover:translate-x-0.5"
72+ >
73+ Clear cache
74+ </span >
75+ </button >
5376 <button
5477 @click =" handleLogout"
5578 class =" group relative flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-sm font-medium text-rose-600 transition-all duration-300 hover:bg-rose-50/60 hover:text-rose-700"
Original file line number Diff line number Diff line change 11<script setup lang="ts">
22import { Link } from ' @inertiajs/vue3' ;
3- import { X , LogOut } from ' lucide-vue-next' ;
3+ import { X , LogOut , Database } from ' lucide-vue-next' ;
44
55defineProps ({
66 navigation: Array ,
@@ -56,7 +56,18 @@ defineEmits(['close', 'logout']);
5656
5757 <div class =" space-y-3" >
5858 <Link
59+ method="post"
60+ href="/admin/clear-cache"
61+ as="button"
62+ class="group flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-sm font-medium text-rose-600 hover:bg-rose-50 /60"
63+ >
64+ <Database class="h-4 w-4" />
65+ Clear Cache
66+ </Link >
67+ <Link
68+ method="post"
5969 href="/logout"
70+ as="button"
6071 class="group flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-sm font-medium text-rose-600 hover:bg-rose-50 /60"
6172 >
6273 <LogOut class="h-4 w-4" />
Original file line number Diff line number Diff line change 1010 use App \Http \Controllers \NodeController ;
1111 use App \Http \Controllers \ResourceController ;
1212 use App \Http \Controllers \SubjectController ;
13+ use Illuminate \Support \Facades \Cache ;
1314 use Illuminate \Support \Facades \Route ;
1415
1516
5152 Route ::post ('/resources/{resource}/patch ' , [AdminResourceController::class, 'update ' ]);
5253
5354 Route ::patch ('/notice ' , [AdminNoticeController::class, 'update ' ])->name ('notice.update ' );
55+ Route ::post ('/clear-cache ' , function () {
56+ Cache ::forget ('home_page_data ' );
57+ return back ()->with ('success ' , 'Cache cleared. ' );
58+ });
5459 });
5560
5661 Route ::prefix ('admin ' )->middleware (['auth ' , 'verified ' , 'role:admin ' ])->name ('admin. ' )->group (function () {
You can’t perform that action at this time.
0 commit comments