Completed
Pull Request — master (#83)
by Sebastian
04:01
created

ArticleRepository::findByUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
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 findByUrl(string $url): Article
20
    {
21
        return Article::online()
22
            ->where('url->'.content_locale(), $url)
23
            ->firstOrFail();
24
    }
25
26
    public static function findSpecialArticle(SpecialArticle $specialArticle): Article
27
    {
28
        return Cache::rememberForever(
29
            "article.specialArticle.{$specialArticle}",
30
            function () use ($specialArticle) {
31
                return Article::where('technical_name', $specialArticle)->firstOrFail();
32
            }
33
        );
34
    }
35
}
36