apollopy/laravel-x-eloquent

增强型Eloquent for Laravel

2.0.0 2018-11-29 19:47 UTC

This package is auto-updated.

Last update: 2024-08-25 19:57:28 UTC


README

安装

composer require apollopy/laravel-x-eloquent

更新composer后,将服务提供者添加到config/app.php文件中的providers数组中

ApolloPY\Eloquent\EloquentServiceProvider::class,

Laravel 5.5使用包自动发现,因此不需要手动添加ServiceProvider。

扩展

sortByIds

$ids = [3, 1, 2];
$posts = Post::find($ids); // collection -> [1, 2, 3]
$posts = $posts->sortByIds($ids); // collection -> [2 => 3, 0 => 1, 1 => 2]
$posts = $posts->values(); // collection -> [3, 1, 2]

chunkByTime

Topic::where('user_id', 1)->chunkByTime(3600, function ($topics) {
    //
});