Completed
Push — master ( 28284e...eaa9bf )
by
unknown
12:07
created

Repository::getById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace App\Repositories;
4
5
use App\Contracts\RepositoryContract;
6
use Illuminate\Database\Eloquent\Model;
7
8
abstract class Repository implements RepositoryContract
9
{
10
    /**
11
     * Ascendent.
12
     */
13
    const ASC = 'asc';
14
15
    /**
16
     * Descendent.
17
     */
18
    const DESC = 'desc';
19
20
    /**
21
     * Find model by id/slug.
22
     *
23
     * @param $slug
24
     * @return Model
25
     */
26 View Code Duplication
    public function find($slug)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        if (is_numeric($slug))
29
            return $this->getModel()->active()->whereId((int) $slug)->first();
30
31
        return $this->getModel()->active()->whereSlug($slug)->first();
32
    }
33
34
    /**
35
     * Lists the columns.
36
     * @example: $collection->lists('name') will return ['id' => 'name', ...] etc.
37
     *
38
     * @param $column
39
     * @param null $key
40
     * @param bool $active
41
     * @return array
42
     */
43
    public function lists($column, $key = null, $active = false)
44
    {
45
        $items = [];
46
47
        $collection = $active ? $this->getModel()->active()->get() : $this->getModel()->all();
48
49
        foreach ($collection as $item)
50
        {
51
            $items[$item->$key] = $item->$column;
52
        }
53
54
        return $items;
55
    }
56
}