Aloia CMS 3.2.0 has been released with Laravel 8 support and improved getter and setter methods.
Here are the improvements as they’ve been implemented:
This change introduces a backward compatible change in getting and setting data on models:
Changes
- addMatter(string $key, $value) is deprecated and now calls set(string $key, $value) under the hood
- setMatter(array $matter) now won’t overwrite data that wasn’t provided in the input array. (example below)
- __get(string $key) now calls get(string $key) under the hood, instead of directly accessing the matter array
Additions
- Added has(string $key) method to check if data is present in the model.
- Added get(string $key) method as a cleaner way to get a single value from the model.
- Added set(string $key, $value) method as a better named alternative to addMatter().
- Added remove(string $key) method to remove a data key from the model.
Example
When you set initial values on a model:
$article = \AloiaCms\Models\Article::find('testing')
->setMatter([
'title' => 'Article title',
'description' => 'description'
]);
And then set more data but with different keys:
$article = \AloiaCms\Models\Article::find('testing')
->setMatter([
'summary' => 'Article summary',
'description' => 'Article description'
]);
will now result in data that looks like this:
[
'title' => 'Article title',
'description' => 'Article description',
'summary' => 'Article summary'
];
instead of what it resulted in before this change:
[
'description' => 'Article description',
'summary' => 'Article summary'
];
Only the provided keys are overwritten. So using setMatter() is no longer necessarily a destructive action.