|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelFlare\Flare\Admin\Models\Users; |
|
4
|
|
|
|
|
5
|
|
|
use LaravelFlare\Flare\Admin\Models\ModelAdmin; |
|
6
|
|
|
use LaravelFlare\Flare\Admin\Models\Traits\ModelWriting; |
|
7
|
|
|
use LaravelFlare\Flare\Admin\Models\Traits\HumanTimestampAttributes; |
|
8
|
|
|
|
|
9
|
|
|
class UserAdmin extends ModelAdmin |
|
10
|
|
|
{ |
|
11
|
|
|
use HumanTimestampAttributes; |
|
12
|
|
|
use ModelWriting; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Managed Model Instance. |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $managedModel = \App\User::class; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* ManagedModel Icon. |
|
23
|
|
|
* |
|
24
|
|
|
* Font Awesome Defined Icon, eg 'user' = 'fa-user' |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $icon = 'user'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Columns for Model. |
|
32
|
|
|
* |
|
33
|
|
|
* Defines which fields to show in the listing tables output. |
|
34
|
|
|
* |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $columns = [ |
|
38
|
|
|
'id' => 'ID', |
|
39
|
|
|
'name', |
|
40
|
|
|
'email', |
|
41
|
|
|
'created_at' => 'Created', |
|
42
|
|
|
'updated_at' => 'Updated', |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Map User Attributes to their Attribute Types. |
|
47
|
|
|
* |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $fields = [ |
|
51
|
|
|
'name' => ['type' => 'text', 'length' => 32, 'required' => 'required'], |
|
52
|
|
|
'email' => ['type' => 'email', 'length' => 255, 'required' => 'required'], |
|
53
|
|
|
'password' => ['type' => 'password', 'length' => 32, 'required' => 'required'], |
|
54
|
|
|
]; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Validation Rules for onCreate, onEdit actions. |
|
58
|
|
|
* |
|
59
|
|
|
* @var array |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $rules = [ |
|
62
|
|
|
'name' => 'required|max:32', |
|
63
|
|
|
'email' => 'required|email', |
|
64
|
|
|
'password' => 'required|min:8|max:32', |
|
65
|
|
|
]; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* The number of models to return for pagination. |
|
69
|
|
|
* |
|
70
|
|
|
* If int greater than 0 then pagination is used, otherwise |
|
71
|
|
|
* all entries will be output. |
|
72
|
|
|
* |
|
73
|
|
|
* @var int |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $perPage = 10; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* When a new password is set, hash it. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function setPasswordAttribute($value) |
|
83
|
|
|
{ |
|
84
|
|
|
if ($value == '') { |
|
85
|
|
|
return; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$this->model->setAttribute('password', bcrypt($value)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Don't output passwords. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function getPasswordAttribute() |
|
97
|
|
|
{ |
|
98
|
|
|
return; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|