File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 17
17
18
18
namespace Colopl \Spanner \Query ;
19
19
20
+ use Closure ;
20
21
use Colopl \Spanner \Connection ;
21
22
use Illuminate \Contracts \Support \Arrayable ;
22
23
use Illuminate \Database \Query \Builder as BaseBuilder ;
@@ -61,13 +62,23 @@ public function update(array $values)
61
62
/**
62
63
* @inheritDoc
63
64
*/
64
- public function updateOrInsert (array $ attributes , array $ values = [])
65
+ public function updateOrInsert (array $ attributes , array | callable $ values = [])
65
66
{
66
- if (! $ this ->where ($ attributes )->exists ()) {
67
+ $ exists = $ this ->where ($ attributes )->exists ();
68
+
69
+ if ($ values instanceof Closure) {
70
+ $ values = $ values ($ exists );
71
+ }
72
+
73
+ if (! $ exists ) {
67
74
return $ this ->insert (array_merge ($ attributes , $ values ));
68
75
}
69
76
70
- return (bool ) $ this ->take (1 )->update (Arr::except ($ values , array_keys ($ attributes )));
77
+ if (empty ($ values )) {
78
+ return true ;
79
+ }
80
+
81
+ return (bool ) $ this ->limit (1 )->update (Arr::except ($ values , array_keys ($ attributes )));
71
82
}
72
83
73
84
/**
You can’t perform that action at this time.
0 commit comments