4
4
use Illuminate \Database \Eloquent \Relations \Relation ;
5
5
use MongoCursor ;
6
6
7
- class Builder extends EloquentBuilder {
8
-
7
+ class Builder extends EloquentBuilder
8
+ {
9
9
/**
10
10
* The methods that should be returned from query builder.
11
11
*
@@ -26,8 +26,7 @@ public function update(array $values)
26
26
{
27
27
// Intercept operations on embedded models and delegate logic
28
28
// to the parent relation instance.
29
- if ($ relation = $ this ->model ->getParentRelation ())
30
- {
29
+ if ($ relation = $ this ->model ->getParentRelation ()) {
31
30
$ relation ->performUpdate ($ this ->model , $ values );
32
31
33
32
return 1 ;
@@ -46,8 +45,7 @@ public function insert(array $values)
46
45
{
47
46
// Intercept operations on embedded models and delegate logic
48
47
// to the parent relation instance.
49
- if ($ relation = $ this ->model ->getParentRelation ())
50
- {
48
+ if ($ relation = $ this ->model ->getParentRelation ()) {
51
49
$ relation ->performInsert ($ this ->model , $ values );
52
50
53
51
return true ;
@@ -67,8 +65,7 @@ public function insertGetId(array $values, $sequence = null)
67
65
{
68
66
// Intercept operations on embedded models and delegate logic
69
67
// to the parent relation instance.
70
- if ($ relation = $ this ->model ->getParentRelation ())
71
- {
68
+ if ($ relation = $ this ->model ->getParentRelation ()) {
72
69
$ relation ->performInsert ($ this ->model , $ values );
73
70
74
71
return $ this ->model ->getKey ();
@@ -86,8 +83,7 @@ public function delete()
86
83
{
87
84
// Intercept operations on embedded models and delegate logic
88
85
// to the parent relation instance.
89
- if ($ relation = $ this ->model ->getParentRelation ())
90
- {
86
+ if ($ relation = $ this ->model ->getParentRelation ()) {
91
87
$ relation ->performDelete ($ this ->model );
92
88
93
89
return $ this ->model ->getKey ();
@@ -108,8 +104,7 @@ public function increment($column, $amount = 1, array $extra = [])
108
104
{
109
105
// Intercept operations on embedded models and delegate logic
110
106
// to the parent relation instance.
111
- if ($ relation = $ this ->model ->getParentRelation ())
112
- {
107
+ if ($ relation = $ this ->model ->getParentRelation ()) {
113
108
$ value = $ this ->model ->{$ column };
114
109
115
110
// When doing increment and decrements, Eloquent will automatically
@@ -139,8 +134,7 @@ public function decrement($column, $amount = 1, array $extra = [])
139
134
{
140
135
// Intercept operations on embedded models and delegate logic
141
136
// to the parent relation instance.
142
- if ($ relation = $ this ->model ->getParentRelation ())
143
- {
137
+ if ($ relation = $ this ->model ->getParentRelation ()) {
144
138
$ value = $ this ->model ->{$ column };
145
139
146
140
// When doing increment and decrements, Eloquent will automatically
@@ -174,13 +168,13 @@ protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $o
174
168
$ relationCount = array_count_values ($ query ->lists ($ relation ->getHasCompareKey ()));
175
169
176
170
// Remove unwanted related objects based on the operator and count.
177
- $ relationCount = array_filter ($ relationCount , function ($ counted ) use ($ count , $ operator )
178
- {
171
+ $ relationCount = array_filter ($ relationCount , function ($ counted ) use ($ count , $ operator ) {
179
172
// If we are comparing to 0, we always need all results.
180
- if ($ count == 0 ) return true ;
173
+ if ($ count == 0 ) {
174
+ return true ;
175
+ }
181
176
182
- switch ($ operator )
183
- {
177
+ switch ($ operator ) {
184
178
case '>= ' :
185
179
case '< ' :
186
180
return $ counted >= $ count ;
@@ -197,7 +191,9 @@ protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $o
197
191
$ not = in_array ($ operator , ['< ' , '<= ' , '!= ' ]);
198
192
199
193
// If we are comparing to 0, we need an additional $not flip.
200
- if ($ count == 0 ) $ not = !$ not ;
194
+ if ($ count == 0 ) {
195
+ $ not = !$ not ;
196
+ }
201
197
202
198
// All related ids.
203
199
$ relatedIds = array_keys ($ relationCount );
@@ -218,16 +214,14 @@ public function raw($expression = null)
218
214
$ results = $ this ->query ->raw ($ expression );
219
215
220
216
// Convert MongoCursor results to a collection of models.
221
- if ($ results instanceof MongoCursor)
222
- {
217
+ if ($ results instanceof MongoCursor) {
223
218
$ results = iterator_to_array ($ results , false );
224
219
225
220
return $ this ->model ->hydrate ($ results );
226
221
}
227
222
228
223
// The result is a single object.
229
- elseif (is_array ($ results ) and array_key_exists ('_id ' , $ results ))
230
- {
224
+ elseif (is_array ($ results ) and array_key_exists ('_id ' , $ results )) {
231
225
$ model = $ this ->model ->newFromBuilder ($ results );
232
226
233
227
$ model ->setConnection ($ this ->model ->getConnection ());
@@ -237,5 +231,4 @@ public function raw($expression = null)
237
231
238
232
return $ results ;
239
233
}
240
-
241
234
}
0 commit comments