im quite new in php OOP, and im using laravel has my framework of choice. Im creating a object user and create the record, the only thing i have to do is to check if one of my input fields(not required) was set, if it was set than i have to add in in the user object, but how can i add this property (mobilephone) and value in a exiting object, am i doing it right?.
code:
$user = User::create([
'email' => $userDat['email'],
'name' => $userDat['name'],
'surname' => $userDat['surname'],
]);
if (isset($userDat['mobilephone'])) {
$user->mobilephone = $userDat['mobilephone'];
}