Skip to content

Instantly share code, notes, and snippets.

View hasnhasan's full-sized avatar
🎯
Focusing

Hasan hasnhasan

🎯
Focusing
View GitHub Profile
use Illuminate\Support\Collection;
Collection::macro('reverseNested', function ($childrenField,$parents=[]) {
$result = collect();
foreach ($this->items as $item) {
if ($item->$childrenField) {
$parents[] = $item->name;
$subCategories = collect($item->$childrenField)->map(function($cat) use ($parents){
$cat->parents = $parents;