Completed
Push — master ( d6d863...730950 )
by Freek
22:10 queued 19:06
created

ArticleRepository::findBySlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Repositories;
4
5
use App\Models\Article;
6
use App\Models\Enums\SpecialArticle;
7
use Illuminate\Support\Collection;
8
use Illuminate\Support\Facades\Cache;
9
10
class ArticleRepository
11
{
12
    public static function getTopLevel(): Collection
13
    {
14
        return Article::where('parent_id', null)
15
            ->orderBy('order_column')
16
            ->get();
17
    }
18
19
    public static function findBySlug(string $url): Article
20
    {
21
        $article =  Article::online()
22
            ->where('url->'.content_locale(), $url)
23
            ->first();
24
25
        abort_unless($article, 404);
26
27
        return $article;
28
    }
29
30
    public static function findSpecialArticle(SpecialArticle $specialArticle): Article
31
    {
32
        return Cache::rememberForever(
33
            "article.specialArticle.{$specialArticle}",
34
            function () use ($specialArticle) {
35
                return Article::where('technical_name', $specialArticle)->firstOrFail();
36
            }
37
        );
38
    }
39
}
40