Collection.php 654 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/9/20
  6. * Time: 上午9:37
  7. */
  8. namespace app\framework\Database\Eloquent;
  9. class Collection extends \Illuminate\Database\Eloquent\Collection
  10. {
  11. public function expansionLoad($relations)
  12. {
  13. if (count($this->items) > 0) {
  14. if (is_string($relations)) {
  15. $relations = func_get_args();
  16. }
  17. /**
  18. * @var Builder $query
  19. */
  20. $query = $this->first()->newQuery()->with($relations);
  21. $this->items = $query->expansionEagerLoadRelations($this->items);
  22. }
  23. return $this;
  24. }
  25. }