Download the PHP package steven-fox/eloquaint without Composer
On this page you can find all versions of the php package steven-fox/eloquaint. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download steven-fox/eloquaint
More information about steven-fox/eloquaint
Files in steven-fox/eloquaint
Package eloquaint
Short Description Reduce the boilerplate in your Eloquent classes.
License MIT
Homepage https://github.com/steven-fox/eloquaint
Informations about the package eloquaint
Experimental!
This project is a work in progress. Expect breaking changes.
Eloquaint - Reduce the boilerplate in your Eloquent classes
Eloquaint allows you to define Laravel Eloquent model relationships and scopes using PHP attributes instead of traditional methods, reducing boilerplate code.
PHP 8.5 Closures as Constant Values
In PHP 8.5, it will be possible to define a closure as a "constant value". In theory, this will enable syntax like:
Thus, we will incorporate these features once PHP 8.5 hits GA and tag a v1.0 release of this package.
Installation
You can install the package via composer:
Basic Usage
Instead of writing traditional relationship and scope methods:
You can now use attributes:
Supported Relationships
Eloquaint supports all Laravel relationship types:
One-to-Many Relationships
One-to-One Relationships
Inverse Relationships
Many-to-Many Relationships
Advanced Relationships
Advanced Features
Custom Relationship Names
Query Constraints
Add where clauses directly to your relationship definitions:
Custom Foreign Keys
Property-Level Attributes
You can also define relationships on properties:
Supported Scopes
Eloquaint also supports defining local scopes using attributes:
Simple Scopes
For basic where clauses, you can define scopes directly:
Complex Scopes
For complex logic, use traditional scope methods alongside simple attribute scopes:
Chaining with Query Methods
Scopes can be chained with regular query methods:
How It Works
- Add the trait: Include
HasEloquaintFeaturesin your model (orHasAttributeRelationsfor relationships only) - Define relationships and scopes: Use PHP attributes on your class
- Use normally: Access relationships and scopes exactly like traditional Eloquent
The package automatically:
- Resolves relationship names (e.g.,
Post::classbecomesposts) - Handles foreign key conventions
- Applies query constraints and scope logic
- Caches definitions for performance
- Supports both static and instance method calls for scopes
Performance
Eloquaint is designed for performance:
- Relationship and scope definitions are cached after first resolution
- No runtime overhead compared to traditional relationships and scopes
- Lazy loading and eager loading work exactly the same
- All Eloquent relationship and scope features are preserved
- Scopes work with both static and instance calls
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Steven Fox
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of eloquaint with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0