Package Data | |
---|---|
Maintainer Username: | iamBiB |
Package Create Date: | 2023-12-17 |
Package Last Update: | 2024-07-26 |
Language: | PHP |
License: | BSD-3-Clause |
Last Refreshed: | 2024-12-17 03:09:58 |
Package Statistics | |
---|---|
Total Downloads: | 1,117 |
Monthly Downloads: | 111 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This is a set of Illuminate\Support\Collection items I use on a daily bases
Laravel / Lumen version 9+
composer require iambib/collection-extender
$collection->recursive();
$collection->pushToKey($key, $value, ?$recursive);
$collection->toModel(?$model_class);
$collection->input($keys,?$default);
$collection->morphTo($object_class)
$array = [
'foo'=>'bar',
'bar'=>[
'foo'=>'Lorem',
'bar'=>'Ipsum',
],
];
Illuminate\Support\Collection {#354 ▼
#items: array:2 [▼
"foo" => "bar"
"bar" => Illuminate\Support\Collection {#358 ▼
#items: array:2 [▼
"foo" => "Lorem"
"bar" => "Ipsum"
]
#escapeWhenCastingToString: false
}
]
#escapeWhenCastingToString: false
}
Illuminate\Support\Collection {#354 ▼
#items: array:2 [▼
"foo" => "bar"
"bar" => Illuminate\Support\Collection {#358 ▼
#items: array:2 [▼
"foo" => "Lorem"
"bar" => "Ipsum"
]
#escapeWhenCastingToString: false
}
]
#escapeWhenCastingToString: false
}
Illuminate\Support\Collection {#354 ▼
#items: array:2 [▼
"foo" => array:2 [▼
0 => "bar"
1 => "newValue"
]
"bar" => Illuminate\Support\Collection {#358 ▼
#items: array:2 [▼
"foo" => "Lorem"
"bar" => "Ipsum"
]
#escapeWhenCastingToString: false
}
]
#escapeWhenCastingToString: false
}
Illuminate\Support\Collection {#352 ▼
#items: array:2 [▼
"foo" => "bar"
"bar" => array:2 [▼
"foo" => "Lorem"
"bar" => "Ipsum"
]
]
#escapeWhenCastingToString: false
}
Which will look for the key that is configured in collection-callback.php as a model_class_key
return [
'model_class_key' => 'model_name',
];
Illuminate\Support\Collection {#353 ▼ // packages/iambib/collection-extender/src/Providers/AppServiceProvider.php:78
#items: array:3 [▼
...
"model_name" => "App\Models\User"
]
#escapeWhenCastingToString: false
}
App\Models\User {#360 ▼
#attributes: array:2 [▼
"foo" => "bar"
"bar" => array:2 [▼
"foo" => "Lorem"
"bar" => "Ipsum"
]
]
#hidden: []
#visible: []
#appends: []
#fillable: []
#guarded: []
#casts: []
#rememberTokenName: "remember_token"
#autoload_relations: []
}
Illuminate\Support\Collection {#352 ▼
#items: array:2 [▼
"foo" => "bar"
"bar" => array:2 [▼
"foo" => "Lorem"
"bar" => "Ipsum"
]
]
#escapeWhenCastingToString: false
}
"Lorem"
"Not found"
Illuminate\Support\Collection {#354 ▼
#items: array:3 [▼
"status" => true
"data" => array:2 [▼
"foo" => "bar"
"bar" => array:2 [▼
"foo" => "Lorem"
"bar" => "Ipsum"
]
]
"message" => "Success"
]
#escapeWhenCastingToString: false
}
ApiResponse {#361 ▼
#status: true
#data: array:2 [▼
"foo" => "bar"
"bar" => array:2 [▼
"foo" => "Lorem"
"bar" => "Ipsum"
]
]
#message: "Success"
#errors: null
}
Hey dude! If you like it .. well or a would be nice :D