Skip to content

Commit 5ee1b95

Browse files
category getAllFromCache
1 parent be4e249 commit 5ee1b95

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

app/Models/Blog/Category.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,19 @@ protected function casts(): array
6161
'is_visible' => 'boolean',
6262
];
6363
}
64+
65+
/**
66+
* Get all categories from cache
67+
*
68+
* @return \Illuminate\Database\Eloquent\Collection<int, static>
69+
*/
70+
public static function getAllFromCache()
71+
{
72+
return cache()->remember('blog_categories', now()->addDay(), function () {
73+
return static::query()
74+
->where('is_visible', true)
75+
->orderBy('name')
76+
->get();
77+
});
78+
}
6479
}

0 commit comments

Comments
 (0)