2
2
3
3
namespace Foxws \WireUse \Forms \Concerns ;
4
4
5
+ use Illuminate \Foundation \Http \FormRequest ;
5
6
use Illuminate \Support \Collection ;
6
7
use Illuminate \Support \Fluent ;
7
8
8
9
trait WithAttributes
9
10
{
10
- protected function keys (): array
11
- {
12
- return array_keys ($ this ->all ());
13
- }
14
-
15
11
public function fill ($ values )
16
12
{
17
- $ values = $ this ->callHook ('beforeFill ' , $ values );
13
+ if (method_exists ($ this , 'beforeFill ' )) {
14
+ $ values = $ this ->beforeFill ($ values );
15
+ }
18
16
19
17
return parent ::fill ($ values );
20
18
}
21
19
22
20
public function get (string $ key , mixed $ default = null ): mixed
23
21
{
24
- return $ this ->getPropertyValue ( $ key) ?: $ default ;
22
+ return $ this ->request ()-> get ( $ key, $ default) ;
25
23
}
26
24
27
25
public function has (...$ properties ): bool
28
26
{
29
- return $ this ->toCollection ()
30
- ->has ($ properties );
27
+ return $ this ->request ()->hasAny ($ properties );
31
28
}
32
29
33
- public function contains (string $ property , mixed $ args ): bool
30
+ public function contains (string $ key , mixed $ value = null ): bool
34
31
{
35
- $ propertyValue = $ this ->get ($ property );
36
-
37
- if (is_array ($ propertyValue )) {
38
- return in_array ($ args , $ propertyValue );
39
- }
40
-
41
- return $ propertyValue === $ args ;
32
+ return $ this ->collect ()->contains ($ key , $ value );
42
33
}
43
34
44
35
public function is (string $ property , mixed $ args = null ): bool
@@ -53,16 +44,12 @@ public function isStrict(string $property, mixed $args = null): bool
53
44
54
45
public function filled (...$ properties ): bool
55
46
{
56
- return $ this ->toCollection ($ properties )
57
- ->filter ()
58
- ->isNotEmpty ();
47
+ return $ this ->request ()->filled ($ properties );
59
48
}
60
49
61
50
public function blank (...$ properties ): bool
62
51
{
63
- return $ this ->toCollection ($ properties )
64
- ->filter ()
65
- ->isEmpty ();
52
+ return ! $ this ->filled ($ properties );
66
53
}
67
54
68
55
public function clear (bool $ submit = true ): void
@@ -76,17 +63,25 @@ public function clear(bool $submit = true): void
76
63
}
77
64
}
78
65
79
- protected function toCollection (...$ properties ): Collection
66
+ protected function keys (): array
67
+ {
68
+ return $ this ->request ()->keys ();
69
+ }
70
+
71
+ protected function request (): FormRequest
72
+ {
73
+ $ this ->validate ();
74
+
75
+ return (new FormRequest ())->merge ($ this ->all ());
76
+ }
77
+
78
+ protected function collect (): Collection
80
79
{
81
- return $ properties
82
- ? new Collection ($ this ->only (...$ properties ))
83
- : new Collection ($ this ->all ());
80
+ return $ this ->request ()->collect ();
84
81
}
85
82
86
- protected function toFluent (... $ properties ): Fluent
83
+ protected function fluent ( ): Fluent
87
84
{
88
- return $ properties
89
- ? new Fluent ($ this ->only (...$ properties ))
90
- : new Fluent ($ this ->all ());
85
+ return request ()->fluent ();
91
86
}
92
87
}
0 commit comments