Skip to content

Commit

Permalink
Merge pull request #5454 from mis3085/fix_grid_model_setsort_is_relation
Browse files Browse the repository at this point in the history
修正Grid無法對關聯欄位使用sortable()的問題
  • Loading branch information
jxlwqq authored Nov 1, 2021
2 parents 8189b3e + 8ce1017 commit 6d12f77
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Grid/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ protected function setSort()

$columnNameContainsDots = Str::contains($columnName, '.');
$isRelation = $this->queries->contains(function ($query) use ($columnName) {
// relationship should be camel case
$columnName = Str::camel(Str::before($columnName, '.'));

return $query['method'] === 'with' && in_array($columnName, $query['arguments'], true);
});
if ($columnNameContainsDots === true && $isRelation) {
Expand Down Expand Up @@ -570,6 +573,8 @@ protected function setSort()
protected function setRelationSort($column)
{
list($relationName, $relationColumn) = explode('.', $column);
// relationship should be camel case
$relationName = Str::camel($relationName);

if ($this->queries->contains(function ($query) use ($relationName) {
return $query['method'] == 'with' && in_array($relationName, $query['arguments']);
Expand Down

0 comments on commit 6d12f77

Please sign in to comment.