File tree 2 files changed +6
-8
lines changed
src/Illuminate/Database/Concerns
2 files changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -81,14 +81,12 @@ public function first($columns = ['*'])
81
81
*/
82
82
public function when ($ value , $ callback , $ default = null )
83
83
{
84
- $ builder = $ this ;
85
-
86
84
if ($ value ) {
87
- $ builder = $ callback ($ builder , $ value );
85
+ return $ callback ($ builder , $ value ) ?: $ this ;
88
86
} elseif ($ default ) {
89
- $ builder = $ default ($ builder , $ value );
87
+ return $ default ($ builder , $ value ) ?: $ this ;
90
88
}
91
89
92
- return $ builder ;
90
+ return $ this ;
93
91
}
94
92
}
Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ public function testWhenCallback()
135
135
$ callback = function ($ query , $ condition ) {
136
136
$ this ->assertTrue ($ condition );
137
137
138
- return $ query ->where ('id ' , '= ' , 1 );
138
+ $ query ->where ('id ' , '= ' , 1 );
139
139
};
140
140
141
141
$ builder = $ this ->getBuilder ();
@@ -152,13 +152,13 @@ public function testWhenCallbackWithDefault()
152
152
$ callback = function ($ query , $ condition ) {
153
153
$ this ->assertEquals ($ condition , 'truthy ' );
154
154
155
- return $ query ->where ('id ' , '= ' , 1 );
155
+ $ query ->where ('id ' , '= ' , 1 );
156
156
};
157
157
158
158
$ default = function ($ query , $ condition ) {
159
159
$ this ->assertEquals ($ condition , 0 );
160
160
161
- return $ query ->where ('id ' , '= ' , 2 );
161
+ $ query ->where ('id ' , '= ' , 2 );
162
162
};
163
163
164
164
$ builder = $ this ->getBuilder ();
You can’t perform that action at this time.
0 commit comments