Skip to content

Commit

Permalink
More simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
shaedrich committed Dec 16, 2024
1 parent 0a88e50 commit aa0b887
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
43 changes: 20 additions & 23 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,10 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
{
$this->query->addSelect($this->shouldSelect($columns));

return tap($this->query->paginate($perPage, $columns, $pageName, $page), function ($paginator) {
$this->hydratePivotRelation($paginator->items());
});
return tap(
$this->query->paginate($perPage, $columns, $pageName, $page),
fn ($paginator) => $this->hydratePivotRelation($paginator->items()),
);
}

/**
Expand Down Expand Up @@ -1083,11 +1084,7 @@ public function each(callable $callback, $count = 1000)
*/
public function lazy($chunkSize = 1000)
{
return $this->prepareQueryBuilder()->lazy($chunkSize)->map(function ($model) {
$this->hydratePivotRelation([$model]);

return $model;
});
return $this->prepareQueryBuilder()->lazy($chunkSize)->map($this->hydratePivotRelationFluent(...));
}

/**
Expand All @@ -1106,11 +1103,9 @@ public function lazyById($chunkSize = 1000, $column = null, $alias = null)

$alias ??= $this->getRelatedKeyName();

return $this->prepareQueryBuilder()->lazyById($chunkSize, $column, $alias)->map(function ($model) {
$this->hydratePivotRelation([$model]);

return $model;
});
return $this->prepareQueryBuilder()
->lazyById($chunkSize, $column, $alias)
->map($this->hydratePivotRelationFluent(...));
}

/**
Expand All @@ -1129,11 +1124,10 @@ public function lazyByIdDesc($chunkSize = 1000, $column = null, $alias = null)

$alias ??= $this->getRelatedKeyName();

return $this->prepareQueryBuilder()->lazyByIdDesc($chunkSize, $column, $alias)->map(function ($model) {
$this->hydratePivotRelation([$model]);

return $model;
});
return $this
->prepareQueryBuilder()
->lazyByIdDesc($chunkSize, $column, $alias)
->map($this->hydratePivotRelationFluent(...));
}

/**
Expand All @@ -1143,11 +1137,7 @@ public function lazyByIdDesc($chunkSize = 1000, $column = null, $alias = null)
*/
public function cursor()
{
return $this->prepareQueryBuilder()->cursor()->map(function ($model) {
$this->hydratePivotRelation([$model]);

return $model;
});
return $this->prepareQueryBuilder()->cursor()->map($this->hydratePivotRelationFluent(...));
}

/**
Expand Down Expand Up @@ -1635,4 +1625,11 @@ public function qualifyPivotColumn($column)
? $column
: $this->table.'.'.$column;
}

private function hydratePivotRelationFluent($model)
{
$this->hydratePivotRelation([$model]);

return $model;
}
}
7 changes: 2 additions & 5 deletions src/Illuminate/Foundation/Console/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,8 @@ protected function getRoutes()
return $this->getRouteInformation($route);
})->filter()->all();

if (($sort = $this->option('sort')) !== null) {
$routes = $this->sortRoutes($sort, $routes);
} else {
$routes = $this->sortRoutes('uri', $routes);
}
$sort = $this->option('sort') ?? 'uri';
$routes = $this->sortRoutes($sort, $routes);

if ($this->option('reverse')) {
$routes = array_reverse($routes);
Expand Down

0 comments on commit aa0b887

Please sign in to comment.