Last active
November 5, 2021 09:58
-
-
Save gander/c7d8af73cc715fa8e12d5c4be63c4975 to your computer and use it in GitHub Desktop.
Laravel when Closure $callback snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$callback = function () { | |
}; | |
collect()->when($callback, static function (\Illuminate\Support\Collection $collection, \Closure $callback) { | |
return \Illuminate\Support\Collection::wrap($callback($collection)); | |
}); // Same as \DB::query()->get(), Model::query()->get() | |
\DB::query()->when($callback, static function (\Illuminate\Database\Query\Builder $query, \Closure $callback) { | |
$callback($query); | |
}); // Same as Model::query() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment