Description
What needs to be done?
- Update project dependencies to ensure compatibility: upgrade Laravel to version
>=12.28 and update all required dependencies accordingly to avoid conflicts and runtime errors, since the getPrevious method is not available in earlier Laravel versions. - Add the following methods to the
ModelTrait:
public function wasExchanged(string $fieldName): bool
{
return $this->wasChanged($fieldName) && !is_null($this->origin($fieldName));
}
public function wasFilled(string $fieldName): bool
{
return $this->wasChanged($fieldName) && is_null($this->origin($fieldName));
}
public function wasCleared(string $fieldName): bool
{
return $this->wasChanged($fieldName) && is_null($this->getAttribute($fieldName));
}
public function origin(string $fieldName): mixed
{
return Arr::get($this->getPrevious(), $fieldName);
}
- Implement unit tests to cover the functionality of both methods, ensuring they work correctly under various scenarios.
Expected Outcome
- The
ModelTrait includes the wasExchanged , wasFilled, wasCleared and origin methods. - Each new methods have comprehensive test coverage validating their expected behavior.
- Tests verify correct detection of changed fields and retrieval of previous values.
- Project dependencies are updated, and Laravel version is
>=12.28 with no dependency conflicts.
Verification Scenarios
- Test
wasExchanged returns true only when a specified field has changed and its previous value is not null. - Test
wasFilled returns true only when a specified field has changed and its previous value is null. - Test
wasCleared returns true only when a specified field has changed and its current value is null. - Test
origin retrieves the previous value of a given field accurately. - Confirm behavior when fields are unchanged or previous values are null.
- Verify methods handle edge cases and invalid inputs gracefully.
- Ensure all tests pass successfully in the test suite.
- Confirm the application runs correctly after dependency updates without errors.
Resources
Description
What needs to be done?
>=12.28and update all required dependencies accordingly to avoid conflicts and runtime errors, since thegetPreviousmethod is not available in earlier Laravel versions.ModelTrait:Expected Outcome
ModelTraitincludes thewasExchanged,wasFilled,wasClearedandoriginmethods.>=12.28with no dependency conflicts.Verification Scenarios
wasExchangedreturns true only when a specified field has changed and its previous value is not null.wasFilledreturns true only when a specified field has changed and its previous value is null.wasClearedreturns true only when a specified field has changed and its current value is null.originretrieves the previous value of a given field accurately.Resources
ModelTraitcodebase -<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
data-testid="icon"