Completed
Push — master ( b1a1a8...10b90e )
by David
27:55
created

Page::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace App\LaravelRestCms\Page;
2
3
use App\LaravelRestCms\BaseModel;
4
use App\LaravelRestCms\Page\PageDetail;
5
use App\LaravelRestCms\Template\Template;
6
7
class Page extends BaseModel {
8
9
	public static $searchCols = ['nav_name', 'url', 'title'];
10
11
	/**
12
	 * The database table used by the model.
13
	 *
14
	 * @var string
15
	 */
16
	protected $table = 'pages';
17
18
	/**
19
	 * The attributes that are mass assignable.
20
	 *
21
	 * @var array
22
	 */
23
	protected $fillable = ['parent_id', 'template_id', 'nav_name', 'url', 'title', 'created_by', 'updated_by'];
24
25
	/**
26
	 * The attributes excluded from the model's JSON form.
27
	 *
28
	 * @var array
29
	 */
30
	protected $hidden = [];
31
32
	/**
33
	 * Rules to validate when creating a model
34
	 * 
35
	* @var array
36
	 */
37
	protected static $createRules = [
38
		'parent_id' => 'integer',
39
		'template_id' => 'integer',
40
		'nav_name' => 'required',
41
		'url' => 'required|unique:pages',
42
		'title' => 'required',
43
		'created_by' => 'integer',
44
		'updated_by' => 'integer',
45
	];
46
47
	/**
48
	 * Indicates if the model should be attributed with created_by and updated_by
49
	 * 
50
	* @var bool
51
	 */
52
	public $attirbution = true;
53
54
	/**
55
	 * Joins the page_detail table
56
	 * 
57
	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
58
	 */
59
	public function detail()
60
    {
61
        return $this->hasMany(PageDetail::class, 'page_id', 'id');
62
    }
63
64
	/**
65
	 * Joins the templates table
66
	 * 
67
	 * @return \Illuminate\Database\Eloquent\Relations\hasOne
68
	 */
69
	public function template()
70
    {
71
        return $this->hasMany(Template::class, 'id', 'template_id');
72
    }
73
74
	/**
75
	 * Joins the pages table
76
	 * 
77
	 * @return \Illuminate\Database\Eloquent\Relations\hasOne
78
	 */
79
	public function parent()
80
    {
81
        return $this->hasMany(Page::class, 'id', 'parent_id');
82
    }
83
84
}
85