Skip to content

(feat) Attribute-driven model casting#240

Merged
techmahedy merged 3 commits intodoppar:3.xfrom
techmahedy:techmahedy-3.x
Apr 13, 2026
Merged

(feat) Attribute-driven model casting#240
techmahedy merged 3 commits intodoppar:3.xfrom
techmahedy:techmahedy-3.x

Conversation

@techmahedy
Copy link
Copy Markdown
Member

@techmahedy techmahedy commented Apr 13, 2026

This PR introduces a fully attribute-driven casting system for entities, replacing the legacy $casts array with a more modern, type-safe, and extensible approach.

use Phaseolies\Database\Entity\Casts\Attributes\ToDateTime;
use Phaseolies\Database\Entity\Casts\Attributes\ToString;

#[ToDateTime]
protected string $joining_date;

#[ToString]
protected string $salary;

All available shorthand attributes:

#[ToString]      protected string  $name;
#[ToInteger]     protected int     $views;
#[ToFloat]       protected float   $weight;
#[ToBoolean]     protected bool    $is_active;
#[ToDate]        protected string  $birthday;
#[ToDateTime]    protected string  $published_at;
#[ToTimestamp]   protected int     $created_at;
#[ToArray]       protected string  $options;
#[ToJson]        protected string  $tags;
#[ToObject]      protected string  $config;
#[ToCollection]  protected string  $images;

Added support for custom and enum casting via the base #[Transform] attribute:

#[Transform('decimal:2')] protected string $price; 

#[Transform(OrderStatus::class)] protected string $status;

@techmahedy techmahedy added the feat new feature label Apr 13, 2026
@techmahedy techmahedy merged commit 7194807 into doppar:3.x Apr 13, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant