Answers for "laravel model cast array"

PHP
1

laravel model to array

use AppModelsUser;

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

return $user->toArray();
Posted by: Guest on November-04-2021
0

laravel array cast

use IlluminateDatabaseEloquentCastsAsCollection;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'options' => AsCollection::class,
];
Posted by: Guest on December-31-2021

Browse Popular Code Answers by Language