|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Config\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Models\Traits\CrudTrait; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
7
|
|
|
|
|
8
|
|
|
class User extends Model |
|
9
|
|
|
{ |
|
10
|
|
|
use CrudTrait; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
protected $table = 'users'; |
|
13
|
|
|
|
|
14
|
|
|
protected $fillable = ['name', 'email', 'password', 'extras']; |
|
15
|
|
|
|
|
16
|
|
|
public function identifiableAttribute() |
|
17
|
|
|
{ |
|
18
|
|
|
return 'name'; |
|
19
|
|
|
} |
|
20
|
|
|
/** |
|
21
|
|
|
* Get the account details associated with the user. |
|
22
|
|
|
*/ |
|
23
|
|
|
public function accountDetails() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->hasOne('Backpack\CRUD\Tests\config\Models\AccountDetails'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get the articles for this user. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function articles() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->hasMany('Backpack\CRUD\Tests\config\Models\Article'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Get the user roles. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function roles() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->belongsToMany('Backpack\CRUD\Tests\config\Models\Role', 'user_role'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getNameComposedAttribute() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->name.'++'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function comment() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->morphOne('Backpack\CRUD\Tests\config\Models\Comment', 'commentable'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function recommends() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->morphToMany('Backpack\CRUD\Tests\config\Models\Recommend', 'recommendable')->withPivot('text'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function recommendsDuplicate() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->morphToMany('Backpack\CRUD\Tests\config\Models\Recommend', 'recommendable')->withPivot(['text', 'id']); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function bills() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->morphToMany('Backpack\CRUD\Tests\config\Models\Bill', 'billable'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function stars() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->morphMany('Backpack\CRUD\Tests\config\Models\Star', 'starable'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function superArticles() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->belongsToMany('Backpack\CRUD\Tests\config\Models\Article', 'articles_user')->withPivot(['notes', 'start_date', 'end_date']); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function superArticlesDuplicates() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->belongsToMany('Backpack\CRUD\Tests\config\Models\Article', 'articles_user') |
|
82
|
|
|
->withPivot(['notes', 'start_date', 'end_date', 'id']) |
|
83
|
|
|
->using('Backpack\CRUD\Tests\config\Models\SuperArticlePivot'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function universes() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->hasMany('Backpack\CRUD\Tests\config\Models\Universe'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function planets() |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->hasMany('Backpack\CRUD\Tests\config\Models\Planet'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function planetsNonNullable() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->hasMany('Backpack\CRUD\Tests\config\Models\PlanetNonNullable'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function comets() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->hasMany('Backpack\CRUD\Tests\config\Models\Comet'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function bang() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->belongsTo('Backpack\CRUD\Tests\config\Models\Bang', 'bang_relation_field'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function incomes() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->hasMany('Backpack\CRUD\Tests\config\Models\Transaction')->ofType('income'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function expenses() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->hasMany('Backpack\CRUD\Tests\config\Models\Transaction')->ofType('expense'); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
protected function isNotRelation() |
|
122
|
|
|
{ |
|
123
|
|
|
return false; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function isNotRelationPublic($arg) |
|
|
|
|
|
|
127
|
|
|
{ |
|
128
|
|
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|