Completed
Push — dev ( 40c7a5...93901c )
by Zach
03:40
created

Page::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nop 0
rs 10
1
<?php
2
3
namespace Larafolio\Models;
4
5
use Larafolio\Helpers\Sluggable;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class Page extends HasContent
9
{
10
    use Sluggable, SoftDeletes;
11
12
    /**
13
     * The table associated with the model.
14
     *
15
     * @var string
16
     */
17
    protected $table = 'pages';
18
19
    /**
20
     * The attributes that are mass assignable.
21
     *
22
     * @var array
23
     */
24
    protected $fillable = [
25
        'name', 'slug', 'visible', 'order',
26
    ];
27
28
    /**
29
     * Return all visible pages.
30
     *
31
     * @param bool $order If true, order pages by 'order'.
32
     *
33
     * @return \Illuminate\Support\Collection
34
     */
35
    public static function allVisible($order = true)
36
    {
37
        $query = static::where('visible', true);
38
39
        return static::orderAndGroupQuery($query, false, $order);
40
    }
41
42
    /**
43
     * Return all hidden pages.
44
     *
45
     * @param bool $order If true, order pages by 'order'.
46
     *
47
     * @return \Illuminate\Support\Collection
48
     */
49
    public static function allHidden($order = true)
50
    {
51
        $query = static::where('visible', false);
52
53
        return static::orderAndGroupQuery($query, false, $order);
54
    }
55
56
    /**
57
     * Return all pages ordered by 'order'.
58
     *
59
     * @return \Illuminate\Support\Collection
60
     */
61
    public static function allOrdered()
62
    {
63
        $query = static::query();
64
65
        return static::orderAndGroupQuery($query, false, true);
66
    }
67
68
    /**
69
     * Get all pages with given block name.
70
     *
71
     * @param string $blockName Name of block.
72
     *
73
     * @return \Illuminate\Support\Collection
74
     */
75
    public static function hasBlockNamed($blockName)
76
    {
77
        return static::hasRelationshipNamed('pages', 'text_blocks', $blockName);
78
    }
79
80
    /**
81
     * Get all pages with given image name.
82
     *
83
     * @param string $imageName Name of image.
84
     *
85
     * @return \Illuminate\Support\Collection
86
     */
87
    public static function hasImageNamed($imageName)
88
    {
89
        return static::hasRelationshipNamed('pages', 'images', $imageName);
90
    }
91
92
    /**
93
     * Get all pages with given link name.
94
     *
95
     * @param string $linkName Name of link.
96
     *
97
     * @return \Illuminate\Support\Collection
98
     */
99
    public static function hasLinkNamed($linkName)
100
    {
101
        return static::hasRelationshipNamed('pages', 'links', $linkName);
102
    }
103
}
104