Completed
Pull Request — master (#6)
by ARCANEDEV
06:53
created

Page::getSelectData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php namespace Arcanesoft\Seo\Models;
2
3
/**
4
 * Class     Page
5
 *
6
 * @package  Arcanesoft\Seo\Models
7
 * @author   ARCANEDEV <[email protected]>
8
 *
9
 * @property  int             id
10
 * @property  string          name
11
 * @property  string          content
12
 * @property  string          locale
13
 * @property  \Carbon\Carbon  created_at
14
 * @property  \Carbon\Carbon  updated_at
15
 *
16
 * @property  \Illuminate\Database\Eloquent\Collection  footers
17
 */
18
class Page extends AbstractModel
19
{
20
    /* -----------------------------------------------------------------
21
     |  Traits
22
     | -----------------------------------------------------------------
23
     */
24
25
    use Presenters\PagePresenter;
26
27
    /* -----------------------------------------------------------------
28
     |  Properties
29
     | -----------------------------------------------------------------
30
     */
31
32
    /**
33
     * The attributes that are mass assignable.
34
     *
35
     * @var array
36
     */
37
    protected $fillable = ['name', 'content', 'locale'];
38
39
    /**
40
     * The attributes that should be cast to native types.
41
     *
42
     * @var array
43
     */
44
    protected $casts = [
45
        'id' => 'integer',
46
    ];
47
48
    /* -----------------------------------------------------------------
49
     |  Constructor
50
     | -----------------------------------------------------------------
51
     */
52
53
    /**
54
     * Page constructor.
55
     *
56
     * @param  array  $attributes
57
     */
58
    public function __construct(array $attributes = [])
59
    {
60
        parent::__construct($attributes);
61
62
        $this->setConnection(config('arcanesoft.seo.database.connection'));
63
        $this->setPrefix(config('arcanesoft.seo.database.prefix', 'seo_'));
64
    }
65
66
    /* -----------------------------------------------------------------
67
     |  Relationships
68
     | -----------------------------------------------------------------
69
     */
70
71
    /**
72
     * Footer's relationship.
73
     *
74
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
75
     */
76
    public function footers()
77
    {
78
        return $this->hasMany(Footer::class);
79
    }
80
81
    /* -----------------------------------------------------------------
82
     |  Main Methods
83
     | -----------------------------------------------------------------
84
     */
85
86
    /**
87
     * Create a new page.
88
     *
89
     * @param  array  $attributes
90
     *
91
     * @return self
92
     */
93
    public static function createOne(array $attributes)
94
    {
95
        $page = new self($attributes);
96
        $page->save();
97
98
        return $page;
99
    }
100
101
    /**
102
     * Update a page.
103
     *
104
     * @param  array  $attributes
105
     *
106
     * @return bool
107
     */
108
    public function updateOne(array $attributes)
109
    {
110
        return $this->update($attributes);
111
    }
112
113
    /* -----------------------------------------------------------------
114
     |  Check Methods
115
     | -----------------------------------------------------------------
116
     */
117
118
    /**
119
     * Check if the page is deletable.
120
     *
121
     * @return bool
122
     */
123
    public function isDeletable()
124
    {
125
        return $this->footers->isEmpty();
126
    }
127
128
    /* -----------------------------------------------------------------
129
     |  Other Methods
130
     | -----------------------------------------------------------------
131
     */
132
133
    /**
134
     * Get the select input data.
135
     *
136
     * @return \Illuminate\Support\Collection
137
     */
138
    public static function getSelectData()
139
    {
140
        $pages = Page::all(); // TODO: Cache the data ??
141
142
        return $pages->pluck('name', 'id')->prepend('-- Select a page --', 0);
143
    }
144
145
    /**
146
     * Get the show url (Seoable).
147
     *
148
     * @return string
149
     */
150
    public function getShowUrl()
151
    {
152
        return route('admin::seo.footers.show', [$this]);
153
    }
154
155
    /**
156
     * Get the edit url (Seoable).
157
     *
158
     * @return string
159
     */
160
    public function getEditUrl()
161
    {
162
        return route('admin::seo.footers.edit', [$this]);
163
    }
164
}
165