How can I convert array into object $user['name'] >>>> $user->name?
<p>Is there any laravel solution? Collection is not working. Symfony would work too. </p>

<pre><code>    $a = User::all(); //Eloquent Collection &lt;-- i want my method to return this

    $users = User::rating();  //Eloquent Collection &lt;-- i want my method to return Eloquent Collection

    return $users; // array
</code></pre>

<p>Here is my method:</p>

<pre><code>    public static function rating() : array {

    $arr = [];

    $data = static::calculateRating() //array;
    foreach ($data as $item) {
        $user = static::with("reviews")-&gt;find($item-&gt;id);
        $user = collect($user);
        $user-&gt;put("rating", (int)$item-&gt;rate_sum);
        $arr[] = $user;
    }

    return $arr;

}
</code></pre>

<p>So I could use this <code>$user-&gt;name</code> instead of <code>$user['name']</code></p>