Answers for "laravel 8 to array"

PHP
2

laravel model to array

use App\Models\User;

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

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

laravel transform object to array

$users = App\User::all();
$users = $users->toArray();
Posted by: Guest on March-08-2021
0

laravel array cast

use Illuminate\Database\Eloquent\Casts\AsCollection;

/**
 * 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