1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Telefonica\Models\Actors; |
4
|
|
|
|
5
|
|
|
use Muleta\Utils\Modificators\StringModificator; |
6
|
|
|
use Pedreiro\Models\Base; |
7
|
|
|
use Telefonica\Traits\AsHuman; |
8
|
|
|
use Illuminate\Support\Str; |
9
|
|
|
|
10
|
|
|
class Person extends Base// implements \Spatie\MediaLibrary\HasMedia |
11
|
|
|
{ |
12
|
|
|
use AsHuman; |
13
|
|
|
|
14
|
|
|
protected $table = 'persons'; |
15
|
|
|
|
16
|
|
|
public $incrementing = false; |
17
|
|
|
protected $casts = [ |
18
|
|
|
'code' => 'string', |
19
|
|
|
]; |
20
|
|
|
protected $primaryKey = 'code'; |
21
|
|
|
protected $keyType = 'string'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The attributes that are mass assignable. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $fillable = [ |
29
|
|
|
'code', |
30
|
|
|
'name', |
31
|
|
|
'cpf', |
32
|
|
|
'birthday' |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
public $formFields = [ |
36
|
|
|
[ |
37
|
|
|
'name' => 'name', |
38
|
|
|
'label' => 'name', |
39
|
|
|
'type' => 'text' |
40
|
|
|
], |
41
|
|
|
[ |
42
|
|
|
'name' => 'cpf', |
43
|
|
|
'label' => 'cpf', |
44
|
|
|
'type' => 'text' |
45
|
|
|
], |
46
|
|
|
[ |
47
|
|
|
'name' => 'birthday', |
48
|
|
|
'label' => 'birthday', |
49
|
|
|
'type' => 'text' |
50
|
|
|
], |
51
|
|
|
// [ |
52
|
|
|
// 'name' => 'slug', |
53
|
|
|
// 'label' => 'slug', |
54
|
|
|
// 'type' => 'text' |
55
|
|
|
// ], |
56
|
|
|
// [ |
57
|
|
|
// 'name' => 'status', |
58
|
|
|
// 'label' => 'Status', |
59
|
|
|
// 'type' => 'checkbox' |
60
|
|
|
// ], |
61
|
|
|
// [ |
62
|
|
|
// 'name' => 'status', |
63
|
|
|
// 'label' => 'Enter your content here', |
64
|
|
|
// 'type' => 'textarea' |
65
|
|
|
// ], |
66
|
|
|
// ['name' => 'publish_on', 'label' => 'Publish Date', 'type' => 'date'], |
67
|
|
|
// ['name' => 'category_id', 'label' => 'Category', 'type' => 'select', 'relationship' => 'category'], |
68
|
|
|
// ['name' => 'tags', 'label' => 'Tags', 'type' => 'select_multiple', 'relationship' => 'tags'], |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
public $indexFields = [ |
72
|
|
|
'name', |
73
|
|
|
'cpf', |
74
|
|
|
'birthday', |
75
|
|
|
// 'slug', |
76
|
|
|
// 'status' |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
public $validationRules = [ |
80
|
|
|
'name' => 'required|max:255', |
81
|
|
|
'cpf' => 'required|max:100', |
82
|
|
|
// 'slug' => 'required|max:100', |
83
|
|
|
// 'status' => 'boolean', |
84
|
|
|
// 'publish_on' => 'date', |
85
|
|
|
// 'published' => 'boolean', |
86
|
|
|
// 'category_id' => 'required|int', |
87
|
|
|
]; |
88
|
|
|
|
89
|
|
|
public $validationMessages = [ |
90
|
|
|
'name.required' => "Nome é obrigatório." |
91
|
|
|
]; |
92
|
|
|
|
93
|
|
|
public $validationAttributes = [ |
94
|
|
|
'name' => 'Name' |
95
|
|
|
]; |
96
|
|
|
|
97
|
|
|
protected $mappingProperties = array( |
98
|
|
|
/** |
99
|
|
|
* User Info |
100
|
|
|
*/ |
101
|
|
|
'name' => [ |
102
|
|
|
'type' => 'string', |
103
|
|
|
"analyzer" => "standard", |
104
|
|
|
], |
105
|
|
|
'cpf' => [ |
106
|
|
|
'type' => 'string', |
107
|
|
|
"analyzer" => "standard", |
108
|
|
|
], |
109
|
|
|
'email' => [ |
110
|
|
|
'type' => 'string', |
111
|
|
|
"analyzer" => "standard", |
112
|
|
|
], |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Grupo de Usuário: |
116
|
|
|
* |
117
|
|
|
* 3 -> Usuário de Produtora |
118
|
|
|
* Default: 3 |
119
|
|
|
*/ |
120
|
|
|
'role_id' => [ |
121
|
|
|
'type' => 'string', |
122
|
|
|
"analyzer" => "standard", |
123
|
|
|
], |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
public function users() |
127
|
|
|
{ |
128
|
|
|
return $this->morphedByMany(\Illuminate\Support\Facades\Config::get('sitec.core.models.user', \App\Models\User::class), 'personable'); //, 'businessable_type', 'businessable_code'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public static function boot() |
132
|
|
|
{ |
133
|
|
|
parent::boot(); |
134
|
|
|
self::creating(function (Person $model) { |
135
|
|
|
if ($model->code=='') { |
136
|
|
|
$model->code = StringModificator::cleanCodeSlug($model->name); |
137
|
|
|
} |
138
|
|
|
}); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|