I am writing code to sort eloquent relationship instance in the parent.
$categories = CategoryMain::with('subs')->get();
foreach($categories as &$category){
$category->sub = $category->subs->sortBy('name');
}
I get the correct arrangement inside the foreach loop, which i verify by doing die(var_dump());,
However, once it is outside, it seems like it is not changed at all. Why is it happening?
$category->save()subvssubs. Are you sure you've spelled these correctly?