Skip to content

Commit

Permalink
cached category
Browse files Browse the repository at this point in the history
  • Loading branch information
bastihilger committed Jul 8, 2022
1 parent cddbeca commit ddaef23
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Kraenkvisuell\NovaCmsPortfolio\Factories\CategoryFactory;
use Kraenkvisuell\NovaCmsPortfolio\Traits\QueryableByTranslation;
use Spatie\Translatable\HasTranslations;
Expand Down Expand Up @@ -51,4 +52,11 @@ public function slideshows()
->with('artist')
->using(CategorySlideshow::class);
}

public static function getCached()
{
return Cache::remember('cachedCategories.'.app()->getLocale(), now()->addSeconds(10), function () {
return static::all()->sortBy('title')->all();
});
}
}

0 comments on commit ddaef23

Please sign in to comment.