@@ -17,22 +17,33 @@ class EloquentStatement
17
17
*/
18
18
private $ reference ;
19
19
20
- public function __construct (string $ operation , string $ reference )
20
+ /**
21
+ * @var array
22
+ */
23
+ private $ columns ;
24
+
25
+ public function __construct (string $ operation , ?string $ reference , array $ columns = [])
21
26
{
22
27
$ this ->operation = $ operation ;
23
28
$ this ->reference = $ reference ;
29
+ $ this ->columns = $ columns ;
24
30
}
25
31
26
32
public function operation (): string
27
33
{
28
34
return $ this ->operation ;
29
35
}
30
36
31
- public function reference (): string
37
+ public function reference (): ? string
32
38
{
33
39
return $ this ->reference ;
34
40
}
35
41
42
+ public function columns (): array
43
+ {
44
+ return $ this ->columns ;
45
+ }
46
+
36
47
public function output (string $ controller_prefix , string $ context ): string
37
48
{
38
49
$ model = $ this ->determineModel ($ controller_prefix );
@@ -49,6 +60,17 @@ public function output(string $controller_prefix, string $context): string
49
60
}
50
61
}
51
62
63
+ if ($ this ->operation () == 'update ' ) {
64
+ $ columns = '' ;
65
+ if (!empty ($ this ->columns ())) {
66
+ $ columns = implode (', ' , array_map (function ($ column ) {
67
+ return sprintf ("'%s' => \$%s " , $ column , $ column );
68
+ }, $ this ->columns ()));
69
+ }
70
+
71
+ $ code = "$ " . Str::camel ($ model ) . '->update([ ' . $ columns . ']); ' ;
72
+ }
73
+
52
74
if ($ this ->operation () == 'find ' ) {
53
75
if ($ this ->usesQualifiedReference ()) {
54
76
$ model = $ this ->extractModel ();
0 commit comments