Skip to content

Releases: ssntpl/data-fields

v0.4.1 — Remove DataRow::duplicate(); document json read leniency

Choose a tag to compare

@sambhav-aggarwal sambhav-aggarwal released this 20 Jun 16:46

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, and select_multiple reads. 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. Use text for opaque strings — json is 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

Choose a tag to compare

@sambhav-aggarwal sambhav-aggarwal released this 20 Jun 16:34

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 via Castable::castUsing; consumers write DataField::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

  • HasDataFieldsJson trait — replaced by the cast.
  • JsonModeMigration, SchemaValidator, FieldValue, DataSetValue, FieldLike — folded into DataField or no longer needed.
  • DataSet model + trait + data_sets table — grouping is a consuming-app concern; cast-mode containers handle the structured case.
  • Envelope handling ({"version": "1.0", ...} wrapping), strict_writes config, clearDataFieldsCache().

Other improvements

  • ValueCaster accepts FieldType|string at every entry point.
  • DataRow::delete() cascades wrapped in DB::transaction().
  • FILE vs FILES decided by declared type, never by stored structure (empty files round-trips as [], not null).
  • select_* rules use Rule::in() and reject , / | in option keys.
  • data_fields indexed on (owner_id, owner_type, key) as a single composite.
  • auto_load_migrations config flag for consumers who'd rather skip vendor:publish.
  • HasDataFields gains getFieldValue / setFieldValue upsert 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

Choose a tag to compare

@Abhishek5Sharma Abhishek5Sharma released this 10 Dec 07:34
e717c61

What's Changed

Full Changelog: v0.1.6...v0.1.7

v0.1.6

Choose a tag to compare

@Abhishek5Sharma Abhishek5Sharma released this 24 Oct 13:04
75eb583

What's Changed

Full Changelog: v0.1.5...v0.1.6

v0.1.5

Choose a tag to compare

@JYOTSANASHARMAA JYOTSANASHARMAA released this 11 Oct 13:34
b068920

What's Changed

Full Changelog: v0.1.4...v0.1.5

v0.1.4

Choose a tag to compare

@JYOTSANASHARMAA JYOTSANASHARMAA released this 08 Oct 18:10
ce6232e

What's Changed

  • deleting datafields and its subfields along with its files recursively by @JYOTSANASHARMAA in #3

New Contributors

Full Changelog: v0.1.3...v0.1.4

v0.1.3

Choose a tag to compare

@Abhishek5Sharma Abhishek5Sharma released this 29 Sep 07:23
94f7dda

What's Changed

Full Changelog: v0.1.2...v0.1.3

v0.1.2

Choose a tag to compare

@Abhishek5Sharma Abhishek5Sharma released this 26 Sep 10:46
9278ca1

What's Changed

New Contributors

Full Changelog: v0.1.1...v0.1.2

v0.1.1

Choose a tag to compare

@Abhishek5Sharma Abhishek5Sharma released this 25 Sep 08:10
a4b6bff

Full Changelog: v0.1.0...v0.1.1

v0.1.0

Choose a tag to compare

@Abhishek5Sharma Abhishek5Sharma released this 09 Sep 06:27