Add a method in setRawOriginal() in Illuminate/Database/Eloquent/Concerns/HasAttributes #46450
-
Hello, at a certain point in my project, i needed to do this : // allow only one address to be a default billing address
if (array_key_exists('is_billing', $validated))
{
// 1. reset all addresses that could be set as default billing address (updating here won't affect the current model $address)
Auth::user()->addresses()->update(['is_billing' => 0]);
// 2. if the given $address model already have an "original" property : is_billing = 1
// (case : the user submit the <form> without changing something in the default billing address)
// then force the "original" property value to 0 to trigger the update of the field in the database
// (\Illuminate\Database\Eloquent\Concerns\HasAttributes > isDirty/hasChanges)
$address->is_billing = 0;
$address->syncOriginalAttribute('is_billing');
// 3. reset the $address model "attributes" property to 1 before saving.
$address->is_billing = 1;
} and i was wondering if you could add a $address->setRawOriginal('is_billing', 0); Thanks :P |
Beta Was this translation helpful? Give feedback.
Answered by
henzeb
Mar 14, 2023
Replies: 1 comment 6 replies
-
We have setRawAttributes, does that do what you want to achieve? |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
Ronan-Lenor
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have setRawAttributes, does that do what you want to achieve?