Commit 9ea528af authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix website programs view + stale cache crash on deploy

- Use null-coalescing for age_from/age_to/duration_months (columns don't exist yet)
- Handle __PHP_Incomplete_Class from stale cache by re-fetching on type mismatch
- Add cache:clear to deploy entrypoint to prevent stale cache after rebuilds
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent d4ecf0e2
...@@ -17,7 +17,7 @@ class WebsiteDataService ...@@ -17,7 +17,7 @@ class WebsiteDataService
{ {
public function getActivities(Academy $academy): Collection public function getActivities(Academy $academy): Collection
{ {
return Cache::remember( $result = Cache::remember(
"website.{$academy->id}.activities", "website.{$academy->id}.activities",
3600, 3600,
fn () => DB::table('activities') fn () => DB::table('activities')
...@@ -26,11 +26,22 @@ public function getActivities(Academy $academy): Collection ...@@ -26,11 +26,22 @@ public function getActivities(Academy $academy): Collection
->orderBy('sort_order') ->orderBy('sort_order')
->get() ->get()
); );
if (!$result instanceof Collection) {
Cache::forget("website.{$academy->id}.activities");
return DB::table('activities')
->where('academy_id', $academy->id)
->where('is_active', true)
->orderBy('sort_order')
->get();
}
return $result;
} }
public function getPrograms(Academy $academy): Collection public function getPrograms(Academy $academy): Collection
{ {
return Cache::remember( $result = Cache::remember(
"website.{$academy->id}.programs", "website.{$academy->id}.programs",
3600, 3600,
fn () => DB::table('training_programs') fn () => DB::table('training_programs')
...@@ -39,11 +50,22 @@ public function getPrograms(Academy $academy): Collection ...@@ -39,11 +50,22 @@ public function getPrograms(Academy $academy): Collection
->orderBy('sort_order') ->orderBy('sort_order')
->get() ->get()
); );
if (!$result instanceof Collection) {
Cache::forget("website.{$academy->id}.programs");
return DB::table('training_programs')
->where('academy_id', $academy->id)
->where('status', 'active')
->orderBy('sort_order')
->get();
}
return $result;
} }
public function getBranches(Academy $academy): Collection public function getBranches(Academy $academy): Collection
{ {
return Cache::remember( $result = Cache::remember(
"website.{$academy->id}.branches", "website.{$academy->id}.branches",
3600, 3600,
fn () => DB::table('branches') fn () => DB::table('branches')
...@@ -52,6 +74,17 @@ public function getBranches(Academy $academy): Collection ...@@ -52,6 +74,17 @@ public function getBranches(Academy $academy): Collection
->orderByDesc('is_main') ->orderByDesc('is_main')
->get() ->get()
); );
if (!$result instanceof Collection) {
Cache::forget("website.{$academy->id}.branches");
return DB::table('branches')
->where('academy_id', $academy->id)
->where('is_active', true)
->orderByDesc('is_main')
->get();
}
return $result;
} }
public function getStats(Academy $academy): array public function getStats(Academy $academy): array
......
...@@ -35,6 +35,9 @@ if [ ! -L public/storage ]; then ...@@ -35,6 +35,9 @@ if [ ! -L public/storage ]; then
php artisan storage:link --no-interaction php artisan storage:link --no-interaction
fi fi
# Flush stale application cache from previous deploy
php artisan cache:clear 2>/dev/null || true
# Cache configuration for production # Cache configuration for production
php artisan config:cache php artisan config:cache
php artisan route:cache php artisan route:cache
......
...@@ -45,19 +45,19 @@ class="rounded-xl w-full aspect-[16/10] object-cover border border-white/10"> ...@@ -45,19 +45,19 @@ class="rounded-xl w-full aspect-[16/10] object-cover border border-white/10">
<h3 class="text-2xl font-bold text-white">{{ $program->name_ar }}</h3> <h3 class="text-2xl font-bold text-white">{{ $program->name_ar }}</h3>
<div class="flex items-center gap-3 mt-3"> <div class="flex items-center gap-3 mt-3">
@if($program->age_from && $program->age_to) @if(($program->age_from ?? null) && ($program->age_to ?? null))
<span class="inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium bg-[var(--site-accent)]/10 text-[var(--site-accent)] border border-[var(--site-accent)]/20"> <span class="inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium bg-[var(--site-accent)]/10 text-[var(--site-accent)] border border-[var(--site-accent)]/20">
{{ $program->age_from }} - {{ $program->age_to }} سنة {{ $program->age_from }} - {{ $program->age_to }} سنة
</span> </span>
@endif @endif
@if($program->duration_months) @if($program->duration_months ?? null)
<span class="inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium bg-white/5 text-white/70 border border-white/10"> <span class="inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium bg-white/5 text-white/70 border border-white/10">
{{ $program->duration_months }} شهر {{ $program->duration_months }} شهر
</span> </span>
@endif @endif
</div> </div>
@if($program->description_ar) @if($program->description_ar ?? null)
<p class="mt-4 text-white/60 leading-relaxed"> <p class="mt-4 text-white/60 leading-relaxed">
{{ Str::limit($program->description_ar, 200) }} {{ Str::limit($program->description_ar, 200) }}
</p> </p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment