Answer the question
In order to leave comments, you need to log in
How to modify/inherit a collection in laravel?
For a more ordered output in the binding model, I add ordering by the types of certain elements. I add a cycle. And I want to change
so that there is one more nesting by types, I do thisSomeTable::with('SomeRelated')->find($id);
$element->SomeRelated//например
foreach($element->SomeRelated as $key=>$el)
{
$element->SomeRelated[$el->some_id][$el->type]=$el;
}
Indirect modification of overloaded element of Illuminate\Database\Eloquent\Collection has no effect
This means that your changes will not be saved, since you get a copy of the object and not its reference. Anything you ask will just be lost.
Answer the question
In order to leave comments, you need to log in
Collections have transform and groupBy methods . Perhaps one of them will suit you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question