11<?php
22
3+ declare (strict_types=1 );
4+
35namespace App \Actions ;
46
57use App \DTO \ContactDTO ;
68use App \Enums \AiModelCategoryEnum ;
9+ use App \Enums \CacheKeyEnum ;
710use App \Enums \ContactSectionEnum ;
811use App \Models \AiModel ;
912use App \Models \Contact ;
1417use App \Models \Technology ;
1518use Illuminate \Support \Collection ;
1619use Illuminate \Support \Facades \Cache ;
17- use Illuminate \Support \Str ;
1820
1921class ViewDataAction
2022{
@@ -23,7 +25,7 @@ class ViewDataAction
2325 */
2426 public function products (string $ locale ): Collection
2527 {
26- $ key = Str:: slug ( " products_published_ { $ locale}" );
28+ $ key = CacheKeyEnum:: PRODUCTS_PUBLISHED -> forLocale ( $ locale );
2729
2830 return Cache::rememberForever ($ key , function () {
2931 return Product::where ('published ' , true )->orderBy ('order ' )->get ();
@@ -35,7 +37,7 @@ public function products(string $locale): Collection
3537 */
3638 public function services (string $ locale ): Collection
3739 {
38- $ key = Str:: slug ( " services_published_ { $ locale}" );
40+ $ key = CacheKeyEnum:: SERVICES_PUBLISHED -> forLocale ( $ locale );
3941
4042 return Cache::rememberForever ($ key , function () {
4143 return Service::where ('published ' , true )->orderBy ('order ' )->get ();
@@ -47,7 +49,7 @@ public function services(string $locale): Collection
4749 */
4850 public function news (string $ locale ): Collection
4951 {
50- $ key = Str:: slug ( " news_published_ { $ locale}" );
52+ $ key = CacheKeyEnum:: NEWS_PUBLISHED -> forLocale ( $ locale );
5153
5254 return Cache::rememberForever ($ key , function () {
5355 // Eager loaded: the cards read the series title and the author's picture,
@@ -65,7 +67,7 @@ public function news(string $locale): Collection
6567 */
6668 public function technologies (string $ locale ): Collection
6769 {
68- $ key = Str:: slug ( " technologies_published_ { $ locale}" );
70+ $ key = CacheKeyEnum:: TECHNOLOGIES_PUBLISHED -> forLocale ( $ locale );
6971
7072 return Cache::rememberForever ($ key , function () {
7173 return Technology::where ('published ' , true )->orderBy ('order ' )->get ();
@@ -77,7 +79,7 @@ public function technologies(string $locale): Collection
7779 */
7880 public function aiModelGroups (): Collection
7981 {
80- return Cache::rememberForever (' ai_models_active ' , function () {
82+ return Cache::rememberForever (CacheKeyEnum:: AI_MODELS_ACTIVE -> value , function () {
8183 return $ this ->groupAiModelsByCategory (
8284 AiModel::whereNull ('archived_at ' )->orderBy ('order ' )->get ()
8385 );
@@ -89,7 +91,7 @@ public function aiModelGroups(): Collection
8991 */
9092 public function aiModelArchive (): Collection
9193 {
92- return Cache::rememberForever (' ai_models_archived ' , function () {
94+ return Cache::rememberForever (CacheKeyEnum:: AI_MODELS_ARCHIVED -> value , function () {
9395 return $ this ->groupAiModelsByCategory (
9496 AiModel::whereNotNull ('archived_at ' )->with ('replacedBy ' )->orderBy ('order ' )->get ()
9597 );
@@ -116,7 +118,7 @@ private function groupAiModelsByCategory(Collection $models): Collection
116118 */
117119 public function openSource (string $ locale ): Collection
118120 {
119- $ key = Str:: slug ( " open_source_published_ { $ locale}" );
121+ $ key = CacheKeyEnum:: OPEN_SOURCE_PUBLISHED -> forLocale ( $ locale );
120122
121123 return Cache::rememberForever ($ key , function () {
122124 return OpenSource::where ('published ' , true )->orderByDesc ('downloads ' )->get ();
@@ -125,7 +127,7 @@ public function openSource(string $locale): Collection
125127
126128 public function contacts (string $ locale ): \stdClass
127129 {
128- $ key = Str:: slug ( " contacts_published_ { $ locale}" );
130+ $ key = CacheKeyEnum:: CONTACTS_PUBLISHED -> forLocale ( $ locale );
129131
130132 return Cache::rememberForever ($ key , function () use ($ locale ) {
131133 // Ordered by the `sort` field from the YAML files rather than alphabetically:
0 commit comments