Completed
Push — master ( 73f026...dc38fa )
by Sebastian
04:16
created

DbRepository::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Foundation\Repositories;
4
5
use Illuminate\Support\Collection;
6
7
abstract class DbRepository extends BaseRepository implements Repository
8
{
9
    public function getAll() : Collection
10
    {
11
        return $this->query()->get();
12
    }
13
14
    /**
15
     * @return \Illuminate\Database\Eloquent\Model|null
16
     */
17
    public function find(int $id)
18
    {
19
        return $this->query()->find($id);
20
    }
21
22
    /**
23
     * @return \Illuminate\Database\Eloquent\Model|null
24
     */
25
    public function findOnline(int $id)
26
    {
27
        return $this->query()->online()->find($id);
28
    }
29
30
    public function getAllOnline() : Collection
31
    {
32
        return $this->query()
33
            ->online()
34
            ->get();
35
    }
36
37
    /**
38
     * @return \Illuminate\Database\Eloquent\Model|null
39
     */
40
    public function findByUrl(string $url)
41
    {
42
        $model = static::MODEL;
43
44
        if (! isset((new $model)->translatedAttributes)) {
45
            return $this->query()->online()->where('url', $url)->first();
46
        }
47
48
        return $this->query()
49
            ->online()
50
            ->whereTranslation('url', $url, content_locale())
51
            ->first();
52
    }
53
54
55
}
56