1
|
|
|
<?php namespace Arcanedev\LaravelNotes\Models; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class Note |
5
|
|
|
* |
6
|
|
|
* @package Arcanedev\LaravelNotes\Models |
7
|
|
|
* @author ARCANEDEV <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @property int id |
10
|
|
|
* @property string content |
11
|
|
|
* @property int noteable_id |
12
|
|
|
* @property string noteable_type |
13
|
|
|
* @property int author_id |
14
|
|
|
* @property \Carbon\Carbon created_at |
15
|
|
|
* @property \Carbon\Carbon updated_at |
16
|
|
|
* |
17
|
|
|
* @property \Illuminate\Database\Eloquent\Model author |
18
|
|
|
* @property \Illuminate\Database\Eloquent\Model noteable |
19
|
|
|
*/ |
20
|
|
|
class Note extends AbstractModel |
21
|
|
|
{ |
22
|
|
|
/* ----------------------------------------------------------------- |
23
|
|
|
| Properties |
24
|
|
|
| ----------------------------------------------------------------- |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The attributes that are mass assignable. |
29
|
|
|
* |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $fillable = ['content', 'author_id']; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The attributes excluded from the model's JSON form. |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $hidden = ['noteable_id', 'noteable_type']; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The attributes that should be cast to native types. |
43
|
|
|
* |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
protected $casts = [ |
47
|
|
|
'id' => 'integer', |
48
|
|
|
'noteable_id' => 'integer', |
49
|
|
|
'author_id' => 'integer', |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/* ----------------------------------------------------------------- |
53
|
|
|
| Constructor |
54
|
|
|
| ----------------------------------------------------------------- |
55
|
|
|
*/ |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Note constructor. |
59
|
|
|
* |
60
|
|
|
* @param array $attributes |
61
|
|
|
*/ |
62
|
18 |
|
public function __construct(array $attributes = []) |
63
|
|
|
{ |
64
|
18 |
|
parent::__construct($attributes); |
65
|
|
|
|
66
|
18 |
|
$this->setTable($this->getTableFromConfig('notes', 'notes')); |
67
|
18 |
|
} |
68
|
|
|
|
69
|
|
|
/* ----------------------------------------------------------------- |
70
|
|
|
| Relationship |
71
|
|
|
| ----------------------------------------------------------------- |
72
|
|
|
*/ |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* The noteable relationship. |
76
|
|
|
* |
77
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo |
78
|
|
|
*/ |
79
|
3 |
|
public function noteable() |
80
|
|
|
{ |
81
|
3 |
|
return $this->morphTo(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* The author relationship. |
86
|
|
|
* |
87
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
88
|
|
|
*/ |
89
|
9 |
|
public function author() |
90
|
|
|
{ |
91
|
9 |
|
return $this->belongsTo($this->getModelFromConfig('authors')); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|