Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rappasoft committed May 24, 2020
2 parents d066461 + 00c4609 commit df58786
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to `laravel-livewire-tables` will be documented in this file

## [Unreleased]

## [0.1.4] - 2020-05-24

### Changed

- Changed $models to $builder
- Changed callback parameters for sorting to $builder, $direction. (Removed sortField because we know what it is, until someone gives me an example of why it would be beneficial to keep it).

## [0.1.3] - 2020-05-12

### Changed
Expand All @@ -27,7 +34,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file

- Initial release

[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.3...development
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.4...development
[0.1.4]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.2...v0.1.3
[0.1.2]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.0...v0.1.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Of course two links that don't do anything would be useless, here are a list of
| hide() | Hide this component forever |
| isHidden() | This component is currently hidden |

By default all components have access to the `$attributes` and `$options` arrays.
By default, all components have access to the `$attributes` and `$options` arrays.

#### Link Component

Expand Down
18 changes: 9 additions & 9 deletions src/TableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,22 @@ public function render(): View
*/
public function models(): Builder
{
$models = $this->query();
$builder = $this->query();

if ($this->searchEnabled && trim($this->search) !== '') {
$models->where(function (Builder $query) {
$builder->where(function (Builder $builder) {
foreach ($this->columns() as $column) {
if ($column->searchable) {
if (is_callable($column->searchCallback)) {
$query = app()->call($column->searchCallback, ['builder' => $query, 'term' => $this->search]);
$builder = app()->call($column->searchCallback, ['builder' => $builder, 'term' => $this->search]);
} elseif (Str::contains($column->attribute, '.')) {
$relationship = $this->relationship($column->attribute);

$query->orWhereHas($relationship->name, function (Builder $query) use ($relationship) {
$query->where($relationship->attribute, 'like', '%'.$this->search.'%');
$builder->orWhereHas($relationship->name, function (Builder $builder) use ($relationship) {
$builder->where($relationship->attribute, 'like', '%'.$this->search.'%');
});
} else {
$query->orWhere($query->getModel()->getTable().'.'.$column->attribute, 'like', '%'.$this->search.'%');
$builder->orWhere($builder->getModel()->getTable().'.'.$column->attribute, 'like', '%'.$this->search.'%');
}
}
}
Expand All @@ -126,15 +126,15 @@ public function models(): Builder

if (Str::contains($this->sortField, '.')) {
$relationship = $this->relationship($this->sortField);
$sortField = $this->attribute($models, $relationship->name, $relationship->attribute);
$sortField = $this->attribute($builder, $relationship->name, $relationship->attribute);
} else {
$sortField = $this->sortField;
}

if (($column = $this->getColumnByAttribute($this->sortField)) !== null && is_callable($column->sortCallback)) {
return app()->call($column->sortCallback, ['models' => $models, 'sortField' => $sortField, 'sortDirection' => $this->sortDirection]);
return app()->call($column->sortCallback, ['builder' => $builder, 'direction' => $this->sortDirection]);
}

return $models->orderBy($sortField, $this->sortDirection);
return $builder->orderBy($sortField, $this->sortDirection);
}
}

0 comments on commit df58786

Please sign in to comment.