Completed
Push — master ( 03bc6f...00f77b )
by Arjay
11:37
created

EloquentRepository::getByName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 11
rs 9.4285
1
<?php
2
3
namespace Yajra\CMS\Repositories\FileAsset;
4
5
use Yajra\CMS\Entities\FileAsset;
6
use Yajra\CMS\Repositories\RepositoryAbstract;
7
8
/**
9
 * Class FileAssetEloquentRepository
10
 *
11
 * @package Yajra\CMS\Repositories\Article
12
 */
13
class EloquentRepository extends RepositoryAbstract implements Repository
14
{
15
    /**
16
     * Get repository model.
17
     *
18
     * @return \Yajra\CMS\Entities\FileAsset
19
     */
20
    public function getModel()
21
    {
22
        return new FileAsset();
23
    }
24
25
    /**
26
     * Get all file assets.
27
     *
28
     * @return \Illuminate\Database\Eloquent\Collection|static[]
29
     */
30
    public function all()
31
    {
32
        return $this->getModel()->query()->get();
33
    }
34
35
    /**
36
     * Get file asset by name.
37
     *
38
     * @param string $name
39
     * @param null $category
40
     * @return \Yajra\CMS\Entities\FileAsset
41
     */
42
    public function getByName($name, $category = null)
43
    {
44
        if (is_null($category)) {
45
            $category = config('asset.default');
46
        }
47
48
        return $this->getModel()
49
                    ->where('name', $name)
50
                    ->where('category', $category)
51
                    ->first();
52
    }
53
}