Skip to content

Remove jsonable feature in favor of Laravel casts#654

Merged
daftspunk merged 5 commits intooctobercms:feature/lean-modelfrom
Samuell1:refactor/remove-jsonable
Jan 16, 2026
Merged

Remove jsonable feature in favor of Laravel casts#654
daftspunk merged 5 commits intooctobercms:feature/lean-modelfrom
Samuell1:refactor/remove-jsonable

Conversation

@Samuell1
Copy link
Member

Remove HasJsonable trait entirely and migrate to Laravel's $casts:

  • Delete HasJsonable.php
  • Remove trait from Model.php
  • Remove jsonable handling from HasAttributes (attributesToArray,
    getAttributeValue, setAttribute)
  • Remove jsonable handling from Validation trait

Migrate models to use $casts with 'array' type:

  • DeferredBinding: pivot_data
  • User: permissions
  • Role: permissions
  • Preferences: value
  • ExpandoModel: expandoColumn
  • contentfield.stub: fieldName

Breaking change: $jsonable property no longer supported.
Use Laravel's $casts = ['field' => 'array'] instead.

Remove model.beforeGetAttribute, model.getAttribute, model.beforeSetAttribute,
and model.setAttribute events from Database and Halcyon models.

These events fired on every attribute access/mutation, causing significant
overhead (e.g., 50 users × 15 attributes × 2 events = 1,500 event fires
for a simple list). Laravel does not fire events for attribute access.

Breaking change: Code relying on these events will need refactoring.
Sync getAttribute() with Laravel's implementation by adding an early
return for null/empty keys. This prevents unnecessary processing and
matches Laravel 12's behavior.
Remove HasJsonable trait entirely and migrate to Laravel's $casts:
- Delete HasJsonable.php
- Remove trait from Model.php
- Remove jsonable handling from HasAttributes (attributesToArray,
  getAttributeValue, setAttribute)
- Remove jsonable handling from Validation trait

Migrate models to use $casts with 'array' type:
- DeferredBinding: pivot_data
- User: permissions
- Role: permissions
- Preferences: value
- ExpandoModel: expandoColumn
- contentfield.stub: fieldName

Breaking change: $jsonable property no longer supported.
Use Laravel's $casts = ['field' => 'array'] instead.
Replace event-based encryption with direct method overrides:
- Override setAttribute() to encrypt values before storing
- Override getAttributeValue() to decrypt values when reading
- Remove bindEvent calls from initializeEncryptable()

Mark trait as deprecated in favor of Laravel's 'encrypted' cast:
  protected $casts = ['secret' => 'encrypted'];
@Samuell1 Samuell1 requested a review from daftspunk January 15, 2026 22:20
@daftspunk daftspunk changed the base branch from 4.x to feature/lean-model January 16, 2026 21:10
@daftspunk
Copy link
Member

Merged to feature branch. Feel free to keep adding to it. Thanks!

@daftspunk daftspunk merged commit b65593b into octobercms:feature/lean-model Jan 16, 2026
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants