Releases: ssntpl/data-fields
Release list
v0.4.1 — Remove DataRow::duplicate(); document json read leniency
Patch release addressing two items surfaced in post-0.4.0 review.
Breaking removal
DataRow::duplicate() removed
The previous behaviour persisted an orphan row with owner_id = 0 and owner_type = ''. That meant a saved row in data_fields that didn't belong to any real owner — junk-shaped state with no sensible use case.
Replace with one of:
// Clone onto a real owner (recursively re-parents children):
$copy = $row->duplicateInto($newOwner);
// Or, for an unsaved in-memory copy (no DB write, no child copy):
$copy = $row->replicate();duplicateInto($owner) is unchanged.
Documentation
- README field-types table now calls out the lenient string-decode behaviour for
json,array, andselect_multiplereads. If a stored value happens to be a JSON-encoded string (double-encoded or migrated legacy data), the read path decodes it as a recovery measure. Usetextfor opaque strings —jsonis for structured data.
No code change in the read path itself; the behaviour was always there.
Full changelog
See CHANGELOG.md.
v0.4.0 — Cast-mode storage via DataField value object
Ground-up rework of JSON-mode storage. The trait-based HasDataFieldsJson is replaced by a Laravel custom cast that hydrates one self-describing DataField document per JSON column — schema and values merged, no envelope, no separate schema column, multiple "forms" per model.
Pre-release package, no compatibility shim provided. See the migration guide in the README and the CHANGELOG for the full list of breaking changes.
Headline changes
New cast surface
use Ssntpl\DataFields\Support\DataField;
class User extends Model
{
protected $casts = [
'preferences' => DataField::class,
];
}
$user->preferences = DataField::section(items: [
['key' => 'dark_mode', 'type' => 'bool', 'value' => true],
['key' => 'language', 'type' => 'text', 'value' => 'en'],
]);
$user->preferences->dark_mode->value; // bool true
$user->preferences->dark_mode->value = false;
$user->save();Ssntpl\DataFields\Support\DataField— cast value object (Castable,IteratorAggregate,JsonSerializable,ArrayAccess,Countable).Ssntpl\DataFields\Casts\DataFieldCast— Laravel cast (resolved viaCastable::castUsing; consumers writeDataField::class).Ssntpl\DataFields\Support\FieldType— PHP 8.1 backed enum covering all 12 leaf + 3 container types.Ssntpl\DataFields\Concerns\FieldAttributes— shared trait between cast and row modes.
Renames
| Before | After |
|---|---|
Ssntpl\DataFields\Models\DataField (Eloquent model) |
Ssntpl\DataFields\Models\DataRow |
Ssntpl\DataFields\Casts\FieldValueCast |
Ssntpl\DataFields\Casts\RowValueCast |
Ssntpl\DataFields\Traits\HasDataFields |
Ssntpl\DataFields\Concerns\HasDataFields |
Config key data_field_model |
data_row_model |
Column meta_data |
meta |
Constants DataField::BOOL etc. |
FieldType::Bool->value etc. |
DataRow also gains a label column (the short display string) so the description column is freed up for actual long-form helper text — matching the cast-mode shape.
Removed
HasDataFieldsJsontrait — replaced by the cast.JsonModeMigration,SchemaValidator,FieldValue,DataSetValue,FieldLike— folded intoDataFieldor no longer needed.DataSetmodel + trait +data_setstable — grouping is a consuming-app concern; cast-mode containers handle the structured case.- Envelope handling (
{"version": "1.0", ...}wrapping),strict_writesconfig,clearDataFieldsCache().
Other improvements
ValueCasteracceptsFieldType|stringat every entry point.DataRow::delete()cascades wrapped inDB::transaction().FILEvsFILESdecided by declared type, never by stored structure (emptyfilesround-trips as[], not null).select_*rules useRule::in()and reject,/|in option keys.data_fieldsindexed on(owner_id, owner_type, key)as a single composite.auto_load_migrationsconfig flag for consumers who'd rather skipvendor:publish.HasDataFieldsgainsgetFieldValue/setFieldValueupsert helpers.
Migration from 0.2.x
- use Ssntpl\DataFields\Traits\HasDataFields;
+ use Ssntpl\DataFields\Concerns\HasDataFields;
- use Ssntpl\DataFields\Models\DataField;
+ use Ssntpl\DataFields\Models\DataRow;Replace HasDataFieldsJson with the DataField::class cast — see the README's "Migrating from 0.2.x" section for a worked example.
Full changelog
See CHANGELOG.md for the complete list of changes and rationales.
v0.1.7
What's Changed
- Revert "link child to parent data" by @Abhishek5Sharma in #6
Full Changelog: v0.1.6...v0.1.7
v0.1.6
v0.1.5
What's Changed
- updated the package with laravel file updated version by @JYOTSANASHARMAA in #4
Full Changelog: v0.1.4...v0.1.5
v0.1.4
What's Changed
- deleting datafields and its subfields along with its files recursively by @JYOTSANASHARMAA in #3
New Contributors
- @JYOTSANASHARMAA made their first contribution in #3
Full Changelog: v0.1.3...v0.1.4
v0.1.3
v0.1.2
What's Changed
- define data fields type and cast by @Abhishek5Sharma in #1
New Contributors
- @Abhishek5Sharma made their first contribution in #1
Full Changelog: v0.1.1...v0.1.2
v0.1.1
v0.1.0
Full Changelog: https://github.com/ssntpl/data-fields/commits/v0.1.0