lastdragon-ru/lara-asp-eloquent
| Install | |
|---|---|
composer require lastdragon-ru/lara-asp-eloquent |
|
| Latest Version: | 11.2.1 |
| PHP: | ^8.4|^8.5 |
| Laravel: | 13 |
| Older releases: | 8 – 12 |
| License: | MIT |
| Last Updated: | Oct 29, 2026 |
| Links: | GitHub · Packagist |
(Laravel) Eloquent Helpers
This package contains useful extensions and mixins for Eloquent.
[include:artisan]: https://github.com/LastDragon-ru/lara-asp-eloquent/blob/HEAD/<lara-asp-documentator:requirements "{$directory}"> //: # (start: preprocess/78cfc4c7c7c55577) //: # (warning: Generated automatically. Do not edit.)
Requirements
| Requirement | Constraint | Supported by |
|---|---|---|
| PHP | ^8.5 |
HEAD ⋯ 11.0.0 |
^8.4 |
HEAD ⋯ 8.0.0 |
|
^8.3 |
10.3.0 ⋯ 5.0.0 |
|
^8.2 |
7.2.0 ⋯ 2.0.0 |
|
^8.1 |
6.4.2 ⋯ 2.0.0 |
|
^8.0 |
4.6.0 ⋯ 2.0.0 |
|
^8.0.0 |
1.1.2 ⋯ 0.12.0 |
|
>=8.0.0 |
0.11.0 ⋯ 0.4.0 |
|
>=7.4.0 |
0.3.0 ⋯ 0.1.0 |
|
| Laravel | ^13.10.0 |
HEAD ⋯ 11.1.0 |
^13.0.0 |
11.0.0 |
|
^12.0.1 |
10.3.0 ⋯ 9.0.0 |
|
^11.0.8 |
8.1.1 ⋯ 8.0.0 |
|
^11.0.0 |
7.2.0 ⋯ 6.2.0 |
|
^10.34.0 |
7.2.0 ⋯ 6.2.0 |
|
^10.0.0 |
6.1.0 ⋯ 2.1.0 |
|
^9.21.0 |
5.6.0 ⋯ 5.0.0-beta.1 |
|
^9.0.0 |
5.0.0-beta.0 ⋯ 0.12.0 |
|
^8.22.1 |
3.0.0 ⋯ 0.2.0 |
|
^8.0 |
0.1.0 |
Installation
composer require lastdragon-ru/lara-asp-eloquent
Iterators
Iterators are similar to Builder::chunk() but uses generators instead of \Closure that makes code more readable:
$query = \App\Models\User::query();
$query->chunk(100, function ($users) {
foreach ($users as $user) {
// ...
}
});
foreach ($query->getChunkedIterator() as $user) {
// ...
}
Iterators also support limit/offset, by default it will try to get them from the Builder, but you can also set them by hand:
$query = \App\Models\User::query()->offset(10)->limit(20);
foreach ($query->getChunkedIterator() as $user) {
// ... 20 items from 10
}
foreach ($query->getChunkedIterator()->setOffset(0) as $user) {
// ...20 items from 0
}
When you use the default ChunkedIterator you should not modify/delete the items while iteration or you will get unexpected results (eg missing items). If you need to modify/delete items while iteration you can use ChunkedChangeSafeIterator that specially created for this case and unlike standard chunkById() it is always safe (please see https://github.com/laravel/framework/issues/35400 for more details). But there are few limitations:
- it is not possible to sort rows, they always will be sorted by
column asc; - the
columnshould not be changed while iteration or this may lead to repeating row in results; - the row inserted while iteration may be skipped if it has
columnwith the value that lover than the internal pointer; - queries with UNION is not supported;
offsetfrom Builder will not be used;
To create a change safe instance you can use:
$query = \App\Models\User::query();
foreach ($query->getChangeSafeIterator() as $user) {
// ...
}
Mixins
\Illuminate\Database\Eloquent\Builder
| Name | Description |
|---|---|
orderByKey(string $direction = 'asc') |
Add an ORDER BY primary_key clause to the query. |
orderByKeyDesc() |
Alias of orderByKey('desc') |
getChunkedIterator() |
Return ChunkedIterator instance. |
getChangeSafeIteratorIterator() |
Return ChunkedChangeSafeIterator instance. |
Upgrading
Please follow Upgrade Guide.
Contributing
Please use the main repository to report issues, send pull requests, or ask questions.
Related Packages
A package to help you write expressive defensive code in a functional manner
A simple drop-in solution for providing UUID support for the IDs of your Eloquen...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 11.2.1 | ^8.4| | ^13.10.0 | MIT | |
| 11.2.0 | ^8.4| | ^13.10.0 | MIT | |
| 11.1.1 | ^8.4| | ^13.10.0 | MIT | |
| 11.1.0 | ^8.4| | ^13.10.0 | MIT | |
| 11.0.0 | ^8.4| | ^13.0.0 | MIT | |
| 10.3.0 | ^8.3| | ^12.0.1 | MIT | |
| 10.2.0 | ^8.3| | ^12.0.1 | MIT | |
| 10.1.0 | ^8.3| | ^12.0.1 | MIT | |
| 10.0.0 | ^8.3| | ^12.0.1 | MIT | |
| 9.3.1 | ^8.3| | ^12.0.1 | MIT | |
| 9.3.0 | ^8.3| | ^12.0.1 | MIT | |
| 9.2.0 | ^8.3| | ^12.0.1 | MIT | |
| 9.1.0 | ^8.3| | ^12.0.1 | MIT | |
| 9.0.0 | ^8.3| | ^12.0.1 | MIT | |
| 8.1.1 | ^8.3| | ^11.0.8 | MIT | |
| 8.1.0 | ^8.3| | ^11.0.8 | MIT | |
| 8.0.0 | ^8.3| | ^11.0.8 | MIT | |
| 7.2.0 | ^8.2| | ^10.34.0| | MIT | |
| 7.1.0 | ^8.2| | ^10.34.0| | MIT | |
| 7.0.1 | ^8.2| | ^10.34.0| | MIT | |
| 7.0.0 | ^8.2| | ^10.34.0| | MIT | |
| 6.4.2 | ^8.1| | ^10.34.0| | MIT | |
| 6.4.1 | ^8.1| | ^10.34.0| | MIT | |
| 6.4.0 | ^8.1| | ^10.34.0| | MIT | |
| 6.3.0 | ^8.1| | ^10.34.0| | MIT | |
| 6.2.0 | ^8.1| | ^10.34.0| | MIT | |
| 6.1.0 | ^8.1| | ^10.0.0 | MIT | |
| 6.0.0 | ^8.1| | ^10.0.0 | MIT | |
| 5.6.0 | ^8.1| | ^9.21.0| | MIT | |
| 5.5.0 | ^8.1| | ^9.21.0| | MIT |
Showing the latest 30 of 78. See every release on Packagist
Pre-releases (2)
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 5.0.0-beta.1 | ^8.1| | ^9.21.0| | MIT | |
| 5.0.0-beta.0 | ^8.1| | ^9.0.0| | MIT |