wendelladriel/laravel-lift
Experimental Laravel package that supercharges Eloquent models with typed public properties matching your schema, powered by PHP 8 attributes. Add validation rules and other metadata directly on models and access them via handy methods, using Eloquent events for easy drop-in use.
Developer Productivity & Code Clarity:
$casts, $fillable, $rules) with type-safe, attribute-based declarations on public properties.public string $name), reducing runtime errors and improving IDE support (autocompletion, refactoring).$fillable, $casts, and $rules arrays by defining them directly on properties (e.g., #[Fillable] #[Rules(['required'])] public string $name).Architectural Flexibility:
Product, SaaS Subscription) with many relationships, casts, or validation rules.@Watch) are needed (e.g., audit logs, real-time updates).Use Cases:
#[Cast('float')] public float $price).#[Immutable] public string $sku) from accidental updates.#[BelongsTo(User::class)]) for consistency with property-based configurations.#[Watch(PriceUpdated::class)] public float $price).#[DB(connection: 'tenant_1')]).Team Scalability:
Adopt When:
$fillable/$casts arrays.Look Elsewhere If:
Alternatives to Evaluate:
*"Lift is a game-changer for how we define Laravel models. Today, our Eloquent models are cluttered with
$fillable,$casts, and$rulesarrays—making them hard to read, maintain, and type-check. This package lets us declare model behavior directly on properties using PHP 8 attributes (e.g.,#[Fillable] #[Rules(['required'])] public string $name), which:
- Reduces bugs by enforcing types and validation at the property level.
- Speeds up development by cutting boilerplate (e.g., no more manual
$castsarrays).- Future-proofs our code with features like immutable fields and property-specific events (e.g., trigger alerts when
pricechanges). It’s experimental but aligns with our tech stack (PHP 8+/Laravel 9+). We’d pilot it on ourProductandSubscriptionmodels to validate the ROI in developer productivity and code quality."*
*"Lift replaces Eloquent’s verbose model configurations with type-safe, attribute-based declarations. Here’s why it’s worth trying:
- No More
$fillable/$castsArrays: Define rules, casts, and relationships directly on properties (e.g.,#[Fillable] #[Cast('float')] public float $price).- Strong Typing: IDE support for autocompletion and refactoring (e.g.,
public string $name).- Experimental but Powerful Features:
- Immutable properties: Prevent accidental updates to critical fields (e.g.,
#[Immutable] public string $sku).- Property-specific events: Trigger custom events when a field changes (e.g.,
#[Watch(PriceUpdated::class)]).- Relationships as attributes: Define
BelongsTo,HasMany, etc., without methods (e.g.,#[BelongsTo(User::class)]).- Migration Path: Start with a single model (e.g.,
Product) and expand incrementally. Risk: It’s experimental, but the payoff in cleaner, safer models is worth the pilot. Let’s test it on ourProductmodel first."*
*"Imagine writing models like this:
final class Product { use Lift; #[Fillable] #[Rules(['required', 'string'])] public string $name; #[Cast('float')] #[Immutable] public float $price; #[BelongsTo(User::class)] public User $owner; }No more:
protected $fillable = ['name']; protected $casts = ['price' => 'float']; public function owner() { return $this->belongsTo(User::class); }Benefits:
- Type safety:
public string $nameensures runtime consistency.- Less boilerplate: Attributes replace repetitive array definitions.
- Cool features: Immutable fields, property events, and relationship attributes.
- Future-proof: Built for Laravel’s evolution (e.g., PHP 8.2+ attributes). Downside: Experimental, but the docs are solid and the author is active. Let’s try it on
UserandOrdermodels first."*
How can I help you explore Laravel packages today?