1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Xetaravel\Livewire\Forms; |
6
|
|
|
|
7
|
|
|
use Illuminate\Validation\Rule; |
8
|
|
|
use Livewire\Form; |
9
|
|
|
use Xetaravel\Models\Badge; |
10
|
|
|
|
11
|
|
|
class BadgeForm extends Form |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The role to update. |
15
|
|
|
* |
16
|
|
|
* @var Badge|null |
17
|
|
|
*/ |
18
|
|
|
public ?Badge $badge = null; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The name of the badge. |
22
|
|
|
* |
23
|
|
|
* @var string|null |
24
|
|
|
*/ |
25
|
|
|
public ?string $name = null; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The description of the badge. |
29
|
|
|
* |
30
|
|
|
* @var string|null |
31
|
|
|
*/ |
32
|
|
|
public ?string $description = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The icon of the badge. |
36
|
|
|
* |
37
|
|
|
* @var string|null |
38
|
|
|
*/ |
39
|
|
|
public ?string $icon = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The color of the badge. |
43
|
|
|
* |
44
|
|
|
* @var string|null |
45
|
|
|
*/ |
46
|
|
|
public ?string $color = null; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The type of the badge. |
50
|
|
|
* |
51
|
|
|
* @var string|null |
52
|
|
|
*/ |
53
|
|
|
public ?string $type = null; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The rule of the badge. |
57
|
|
|
* |
58
|
|
|
* @var int|null |
59
|
|
|
*/ |
60
|
|
|
public ?int $rule = null; |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
protected function rules(): array |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
|
|
'name' => [ |
67
|
|
|
'required', |
68
|
|
|
'min:3', |
69
|
|
|
Rule::unique('badges')->ignore($this->badge) |
70
|
|
|
], |
71
|
|
|
'description' => 'min:10', |
72
|
|
|
'icon' => 'required|string', |
73
|
|
|
'color' => 'required|min:7|max:7|hex_color', |
74
|
|
|
'type' => 'required|string', |
75
|
|
|
'rule' => [ |
76
|
|
|
'required', |
77
|
|
|
'int', |
78
|
|
|
Rule::unique('badges') |
79
|
|
|
->ignore($this->badge) |
80
|
|
|
->where(function ($query) { |
81
|
|
|
return $query->where('type', $this->type); |
82
|
|
|
}), |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Function to store the model. |
89
|
|
|
* |
90
|
|
|
* @return Badge |
91
|
|
|
*/ |
92
|
|
|
public function create(): Badge |
93
|
|
|
{ |
94
|
|
|
$properties = [ |
95
|
|
|
'name', |
96
|
|
|
'description', |
97
|
|
|
'icon', |
98
|
|
|
'color', |
99
|
|
|
'type', |
100
|
|
|
'rule', |
101
|
|
|
]; |
102
|
|
|
|
103
|
|
|
return Badge::create($this->only($properties)); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Function to update the model. |
108
|
|
|
* |
109
|
|
|
* @return Badge |
110
|
|
|
*/ |
111
|
|
|
public function update(): Badge |
112
|
|
|
{ |
113
|
|
|
$this->badge->update($this->only([ |
|
|
|
|
114
|
|
|
'name', |
115
|
|
|
'description', |
116
|
|
|
'icon', |
117
|
|
|
'color', |
118
|
|
|
'type', |
119
|
|
|
'rule', |
120
|
|
|
])); |
121
|
|
|
|
122
|
|
|
return $this->badge->fresh(); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.