laravel object to array

84

laravel model to array -

use App\Models\User;

$user = User::with('roles')->first();

return $user->toArray();

laravel transform object to array -

$users = App\User::all();
$users = $users->toArray();

laravel object to array -

function objectToArray(&$object)
{
    return @json_decode(json_encode($object), true);
}

Comments

Submit
0 Comments