apollopy / laravel-x-eloquent by apollopy

Enhanced Eloquent for Laravel
15,519
1
1
Package Data
Maintainer Username: apollopy
Maintainer Contact: ApolloPY@Gmail.com (ApolloPY)
Package Create Date: 2016-02-18
Package Last Update: 2018-12-25
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-05-07 03:05:02
Package Statistics
Total Downloads: 15,519
Monthly Downloads: 57
Daily Downloads: 3
Total Stars: 1
Total Watchers: 1
Total Forks: 0
Total Open Issues: 1

laravel-x-eloquent

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