I want to work with collections even if data is single model:
So if I do collect($collectionOfModels) its do nothing = GOOD.
If I do collect($singleModel) its wraps all model's properties (instead of model) like this:
array:2 [
"id" => 1
"name" => "Alex"
]
But I want this:
array:1 [
array:2 ["id" => 1, "name" => "Alex"],
]
So every time I do that trick:
$collectionOrSingleModel = getData();
if ($collectionOrSingleModel instanceof Model) {
$collectionOrSingleModel = collect([collectionOrSingleModel ]);
}
foreach ($collectionOrSingleModel as $singleModel) {
// ...
}
It works fine but I don't feel good. Is there any better way to do that?