A
A
Abc Edc2015-08-17 21:43:47
Laravel
Abc Edc, 2015-08-17 21:43:47

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 this
SomeTable::with('SomeRelated')->find($id);
$element->SomeRelated//например

foreach($element->SomeRelated as $key=>$el)
{ 
    $element->SomeRelated[$el->some_id][$el->type]=$el;
}

I make a nested array
and catch
Indirect modification of overloaded element of Illuminate\Database\Eloquent\Collection has no effect

How much did it mean
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.

So how to inherit or how to change it the right way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-08-17
@gleber1

Collections have transform and groupBy methods . Perhaps one of them will suit you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question