I'm trying to take $max
results. But sometimes the $max
is NULL, so the query must returns all results.
I use this code:
$results = MyModel::whereIn('player', $players)->take(function($query) use ($max) {
if (isset($max)) {
$query->take($max);
}
})->get();
But i get this error:
[ErrorException]
Object of class Closure could not be converted to int