$user = User::find(1); $userArray = $user->toArray(); // $userArray will now contain an array // of the user's attributes
$users = User::all(); $userArray = $users->toArray(); // $userArray will now contain an array // of arrays, each containing a user's attributesIn this example, all User model instances are converted to an array using the toArray method. This array of arrays can be used to easily serialize and transport multiple users' attributes. This method is part of the Laravel framework's Eloquent ORM package.