To convert an array to Eloquent model in laravel, you typically create a new instance of the model and set the attributes using the array values.
$userData = [
'name' => 'dev',
'email' => 'dev@gmail.com',
'age' => 30
];
$user = new User(); // create an instance of User model $user->name = $userData['name']; $user->email = $userData['email']; $user->age = $userData['age']; $user->save();
Inshort you can fill method to store $userData array to user object
$user->fill($userData);

Leave a Reply