Есть ли решение для laravel? Коллекция не работает. Symfony тоже будет работать.
$a = User::all(); //Eloquent Collection <-- i want my method to return this
$users = User::rating(); //Eloquent Collection <-- i want my method to return Eloquent Collection
return $users; // array
Вот мой метод:
public static function rating() : array {
$arr = [];
$data = static::calculateRating() //array;
foreach ($data as $item) {
$user = static::with("reviews")->find($item->id);
$user = collect($user);
$user->put("rating", (int)$item->rate_sum);
$arr[] = $user;
}
return $arr;
}
Так что я мог бы использовать это $user->name
вместо $user['name']