apollopy/laravel-x-eloquent

Enhanced Eloquent for Laravel

2.0.0 2018-11-29 19:47 UTC

This package is auto-updated.

Last update: 2024-03-25 18:36:29 UTC


README

Installation

composer require apollopy/laravel-x-eloquent

After updating composer, add the service provider to the providers array in config/app.php

ApolloPY\Eloquent\EloquentServiceProvider::class,

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

Extension

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) {
    //
});