diff --git a/src/Http/Livewire/Column.php b/src/Http/Livewire/Column.php index cab6a8c07..63bab3134 100644 --- a/src/Http/Livewire/Column.php +++ b/src/Http/Livewire/Column.php @@ -5,13 +5,10 @@ use Illuminate\Support\Str; /** - * Class Column - * - * @package App\Http\Livewire + * Class Column. */ class Column { - /** * @var */ @@ -53,7 +50,7 @@ class Column protected $html = false; /** - * This column is a custom attribute on the model and not a column in the database + * This column is a custom attribute on the model and not a column in the database. * * @var bool */ @@ -102,17 +99,19 @@ public static function make($text = null, $attribute = null) * * @return $this */ - public function searchable(callable $callable = null) : self + public function searchable(callable $callable = null): self { $this->searchCallback = $callable; $this->searchable = true; + return $this; } /** * @return bool */ - public function isSearchable() : bool { + public function isSearchable(): bool + { return $this->searchable; } @@ -121,64 +120,73 @@ public function isSearchable() : bool { * * @return $this */ - public function sortable(callable $callable = null) : self + public function sortable(callable $callable = null): self { $this->sortCallback = $callable; $this->sortable = true; + return $this; } /** * @return bool */ - public function isSortable() : bool { + public function isSortable(): bool + { return $this->sortable; } /** * @return $this */ - public function unescaped() : self + public function unescaped(): self { $this->unescaped = true; + return $this; } /** * @return bool */ - public function isUnescaped() : bool { + public function isUnescaped(): bool + { return $this->unescaped; } /** * @return $this */ - public function html() : self + public function html(): self { $this->html = true; + return $this; } /** * @return bool */ - public function isHtml() : bool { + public function isHtml(): bool + { return $this->html; } /** * @return $this */ - public function customAttribute() : self { + public function customAttribute(): self + { $this->customAttribute = true; + return $this; } /** * @return bool */ - public function isCustomAttribute() : bool { + public function isCustomAttribute(): bool + { return $this->customAttribute; } @@ -187,16 +195,18 @@ public function isCustomAttribute() : bool { * * @return $this */ - public function view($view) : self + public function view($view): self { $this->view = $view; + return $this; } /** * @return bool */ - public function isView() : bool { + public function isView(): bool + { return view()->exists($this->view); } } diff --git a/src/Http/Livewire/TableComponent.php b/src/Http/Livewire/TableComponent.php index 14f7c02d8..1e4cf9aa2 100644 --- a/src/Http/Livewire/TableComponent.php +++ b/src/Http/Livewire/TableComponent.php @@ -2,11 +2,11 @@ namespace Rappasoft\LivewireTables\Http\Livewire; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Str; use Illuminate\View\View; use Livewire\Component; -use Illuminate\Support\Str; use Livewire\WithPagination; -use Illuminate\Database\Eloquent\Builder; use Rappasoft\LivewireTables\Http\Livewire\Traits\Checkboxes; use Rappasoft\LivewireTables\Http\Livewire\Traits\Loading; use Rappasoft\LivewireTables\Http\Livewire\Traits\Offline; @@ -17,13 +17,10 @@ use Rappasoft\LivewireTables\Http\Livewire\Traits\Yajra; /** - * Class TableComponent - * - * @package App\Http\Livewire + * Class TableComponent. */ abstract class TableComponent extends Component { - use Checkboxes, Loading, Offline, @@ -35,7 +32,7 @@ abstract class TableComponent extends Component Yajra; /** - * The classes applied to the wrapper div + * The classes applied to the wrapper div. * * @var string */ @@ -45,23 +42,25 @@ abstract class TableComponent extends Component * Whether or not to refresh the table at a certain interval * false is off * If it's an integer it will be treated as milliseconds (2000 = refresh every 2 seconds) - * If it's a string it will call that function every 5 seconds + * If it's a string it will call that function every 5 seconds. * * @var bool|string */ public $refresh = false; /** - * Constructor + * Constructor. */ - public function mount() { + public function mount() + { $this->setTranslationStrings(); } /** - * Sets the initial translations of these items + * Sets the initial translations of these items. */ - public function setTranslationStrings() { + public function setTranslationStrings() + { $this->loadingMessage = __('Loading...'); $this->offlineMessage = __('You are not currently connected to the internet.'); $this->noResultsMessage = __('There are no results to display for this query.'); @@ -72,24 +71,25 @@ public function setTranslationStrings() { /** * @return mixed */ - abstract public function query() : Builder; + abstract public function query(): Builder; /** * @return mixed */ - abstract public function columns() : array ; + abstract public function columns(): array; /** * @return string */ - public function view() : string { + public function view(): string + { return 'laravel-livewire-tables::table'; } /** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function render() : View + public function render(): View { return view($this->view(), [ 'columns' => $this->columns(), @@ -100,7 +100,7 @@ public function render() : View /** * @return Builder */ - public function models() : Builder + public function models(): Builder { $models = $this->query(); @@ -112,12 +112,12 @@ public function models() : Builder $query = app()->call($column->searchCallback, ['builder' => $query, '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 . '%'); + $query->where($relationship->attribute, 'like', '%'.$this->search.'%'); }); } else { - $query->orWhere($query->getModel()->getTable() . '.' . $column->attribute, 'like', '%' . $this->search . '%'); + $query->orWhere($query->getModel()->getTable().'.'.$column->attribute, 'like', '%'.$this->search.'%'); } } } diff --git a/src/Http/Livewire/Traits/Checkboxes.php b/src/Http/Livewire/Traits/Checkboxes.php index 91d7ed832..ba1300901 100644 --- a/src/Http/Livewire/Traits/Checkboxes.php +++ b/src/Http/Livewire/Traits/Checkboxes.php @@ -3,69 +3,60 @@ namespace Rappasoft\LivewireTables\Http\Livewire\Traits; /** - * Trait Checkboxes - * - * @package Rappasoft\LivewireTables\Http\Livewire\Traits + * Trait Checkboxes. */ trait Checkboxes { - /** - * Checboxes + * Checboxes. */ /** - * Whether or not checkboxes are enabled + * Whether or not checkboxes are enabled. * * @var bool */ public $checkbox = false; /** - * The side to put the checkboxes on + * The side to put the checkboxes on. * * @var string */ public $checkboxLocation = 'left'; /** - * The model attribute to bind to the checkbox array + * The model attribute to bind to the checkbox array. * * @var string */ public $checkboxAttribute = 'id'; /** - * Whether or not all checkboxes are currently selected + * Whether or not all checkboxes are currently selected. * * @var bool */ public $checkboxAll = false; /** - * The currently selected values of the checkboxes + * The currently selected values of the checkboxes. * * @var array */ public $checkboxValues = []; - /** - * - */ public function updatedCheckboxAll() { $this->checkboxValues = []; if ($this->checkboxAll) { $this->models()->each(function ($model) { - $this->checkboxValues[] = (string)$model->{$this->checkboxAttribute}; + $this->checkboxValues[] = (string) $model->{$this->checkboxAttribute}; }); } } - /** - * - */ public function updatedCheckboxValues() { $this->checkboxAll = false; diff --git a/src/Http/Livewire/Traits/Loading.php b/src/Http/Livewire/Traits/Loading.php index a95a825d6..7508a102d 100644 --- a/src/Http/Livewire/Traits/Loading.php +++ b/src/Http/Livewire/Traits/Loading.php @@ -3,26 +3,23 @@ namespace Rappasoft\LivewireTables\Http\Livewire\Traits; /** - * Trait Loading - * - * @package Rappasoft\LivewireTables\Http\Livewire\Traits + * Trait Loading. */ trait Loading { - /** - * Loading + * Loading. */ /** - * Whether or not to show a loading indicator when searching + * Whether or not to show a loading indicator when searching. * * @var bool */ public $loadingIndicator = false; /** - * The loading message that gets displayed + * The loading message that gets displayed. * * @var string */ diff --git a/src/Http/Livewire/Traits/Offline.php b/src/Http/Livewire/Traits/Offline.php index 02ec73443..dabd4be0d 100644 --- a/src/Http/Livewire/Traits/Offline.php +++ b/src/Http/Livewire/Traits/Offline.php @@ -3,26 +3,23 @@ namespace Rappasoft\LivewireTables\Http\Livewire\Traits; /** - * Trait Offline - * - * @package Rappasoft\LivewireTables\Http\Livewire\Traits + * Trait Offline. */ trait Offline { - /** - * Offline + * Offline. */ /** - * Whether or not to display an offline message when there is no connection + * Whether or not to display an offline message when there is no connection. * * @var bool */ public $offlineIndicator = true; /** - * The message to display when offline + * The message to display when offline. * * @var string */ diff --git a/src/Http/Livewire/Traits/Pagination.php b/src/Http/Livewire/Traits/Pagination.php index da76cb0fc..836920a63 100644 --- a/src/Http/Livewire/Traits/Pagination.php +++ b/src/Http/Livewire/Traits/Pagination.php @@ -3,40 +3,37 @@ namespace Rappasoft\LivewireTables\Http\Livewire\Traits; /** - * Trait Pagination - * - * @package Rappasoft\LivewireTables\Http\Livewire\Traits + * Trait Pagination. */ trait Pagination { - /** - * Pagination + * Pagination. */ /** - * Displays per page and pagination links + * Displays per page and pagination links. * * @var bool */ public $paginationEnabled = true; /** - * The options to limit the amount of results per page + * The options to limit the amount of results per page. * * @var array */ public $perPageOptions = [10, 25, 50]; /** - * Amount of items to show per page + * Amount of items to show per page. * * @var int */ public $perPage = 25; /** - * The label for the per page filter + * The label for the per page filter. * * @var string */ diff --git a/src/Http/Livewire/Traits/Search.php b/src/Http/Livewire/Traits/Search.php index e038417ba..43b00c91b 100644 --- a/src/Http/Livewire/Traits/Search.php +++ b/src/Http/Livewire/Traits/Search.php @@ -3,19 +3,16 @@ namespace Rappasoft\LivewireTables\Http\Livewire\Traits; /** - * Trait Search - * - * @package Rappasoft\LivewireTables\Http\Livewire\Traits + * Trait Search. */ trait Search { - /** - * Search + * Search. */ /** - * Whether or not searching is enabled + * Whether or not searching is enabled. * * @var bool */ @@ -23,35 +20,35 @@ trait Search /** * false = disabled - * int = Amount of time in ms to wait to send the search query and refresh the table + * int = Amount of time in ms to wait to send the search query and refresh the table. * * @var int */ public $searchDebounce = 350; /** - * Whether or not to disable the search bar when it is searching/loading new data + * Whether or not to disable the search bar when it is searching/loading new data. * * @var bool */ public $disableSearchOnLoading = true; /** - * The initial search string + * The initial search string. * * @var string */ public $search = ''; /** - * The placeholder for the search box + * The placeholder for the search box. * * @var string */ public $searchLabel; /** - * The message to display when there are no results + * The message to display when there are no results. * * @var string */ diff --git a/src/Http/Livewire/Traits/Sorting.php b/src/Http/Livewire/Traits/Sorting.php index c05172579..1c65c7868 100644 --- a/src/Http/Livewire/Traits/Sorting.php +++ b/src/Http/Livewire/Traits/Sorting.php @@ -3,26 +3,23 @@ namespace Rappasoft\LivewireTables\Http\Livewire\Traits; /** - * Trait Sorting - * - * @package Rappasoft\LivewireTables\Http\Livewire\Traits + * Trait Sorting. */ trait Sorting { - /** - * Sorting + * Sorting. */ /** - * The initial field to be sorting by + * The initial field to be sorting by. * * @var string */ public $sortField = 'id'; /** - * The initial direction to sort + * The initial direction to sort. * * @var bool */ @@ -31,7 +28,7 @@ trait Sorting /** * @param $attribute */ - public function sort($attribute) : void + public function sort($attribute): void { if ($this->sortField !== $attribute) { $this->sortDirection = 'asc'; diff --git a/src/Http/Livewire/Traits/Table.php b/src/Http/Livewire/Traits/Table.php index ed77474b5..4243baf5e 100644 --- a/src/Http/Livewire/Traits/Table.php +++ b/src/Http/Livewire/Traits/Table.php @@ -3,49 +3,44 @@ namespace Rappasoft\LivewireTables\Http\Livewire\Traits; /** - * Trait Table - * - * @package Rappasoft\LivewireTables\Http\Livewire\Traits + * Trait Table. */ trait Table { - /** - * Table + * Table. */ /** - * Whether or not to display the table header + * Whether or not to display the table header. * * @var bool */ public $tableHeaderEnabled = true; - - /** - * Whether or not to display the table footer + * Whether or not to display the table footer. * * @var bool */ public $tableFooterEnabled = false; /** - * The class to set on the table + * The class to set on the table. * * @var string */ public $tableClass = 'table table-striped'; /** - * The class to set on the thead of the table + * The class to set on the thead of the table. * * @var string */ public $tableHeaderClass = ''; /** - * The class to set on the tfoot of the table + * The class to set on the tfoot of the table. * * @var string */ @@ -53,7 +48,7 @@ trait Table /** * false is off - * string is the tables wrapping div class + * string is the tables wrapping div class. * * @var bool */ @@ -64,7 +59,7 @@ trait Table * * @return string|null */ - public function setTableHeadClass($attribute) : ?string + public function setTableHeadClass($attribute): ?string { return null; } @@ -74,7 +69,7 @@ public function setTableHeadClass($attribute) : ?string * * @return string|null */ - public function setTableHeadId($attribute) : ?string + public function setTableHeadId($attribute): ?string { return null; } @@ -84,7 +79,7 @@ public function setTableHeadId($attribute) : ?string * * @return array|null */ - public function setTableHeadAttributes($attribute) : array + public function setTableHeadAttributes($attribute): array { return []; } @@ -94,7 +89,7 @@ public function setTableHeadAttributes($attribute) : array * * @return string|null */ - public function setTableRowClass($model) : ?string + public function setTableRowClass($model): ?string { return null; } @@ -104,7 +99,7 @@ public function setTableRowClass($model) : ?string * * @return string|null */ - public function setTableRowId($model) : ?string + public function setTableRowId($model): ?string { return null; } @@ -114,7 +109,7 @@ public function setTableRowId($model) : ?string * * @return array */ - public function setTableRowAttributes($model) : array + public function setTableRowAttributes($model): array { return []; } @@ -125,7 +120,7 @@ public function setTableRowAttributes($model) : array * * @return string|null */ - public function setTableDataClass($attribute, $value) : ?string + public function setTableDataClass($attribute, $value): ?string { return null; } @@ -136,7 +131,7 @@ public function setTableDataClass($attribute, $value) : ?string * * @return string|null */ - public function setTableDataId($attribute, $value) : ?string + public function setTableDataId($attribute, $value): ?string { return null; } @@ -147,7 +142,7 @@ public function setTableDataId($attribute, $value) : ?string * * @return array */ - public function setTableDataAttributes($attribute, $value) : array + public function setTableDataAttributes($attribute, $value): array { return []; } diff --git a/src/Http/Livewire/Traits/Yajra.php b/src/Http/Livewire/Traits/Yajra.php index fdab3552c..817a8e142 100644 --- a/src/Http/Livewire/Traits/Yajra.php +++ b/src/Http/Livewire/Traits/Yajra.php @@ -8,9 +8,7 @@ use Illuminate\Database\Eloquent\Relations\HasOneOrMany; /** - * Trait Yajra - * - * @package Rappasoft\LivewireTables\Http\Livewire\Traits + * Trait Yajra. */ trait Yajra { @@ -23,7 +21,7 @@ public function relationship($attribute) { $parts = explode('.', $attribute); - return (object)[ + return (object) [ 'attribute' => array_pop($parts), 'name' => implode('.', $parts), ]; @@ -54,10 +52,10 @@ public function attribute(Builder $query, $relationships, $attribute) $related = $model->getRelated(); $table = $related->getTable(); $tablePK = $related->getForeignKey(); - $foreign = $pivot . '.' . $tablePK; + $foreign = $pivot.'.'.$tablePK; $other = $related->getQualifiedKeyName(); - $last_query->addSelect($table . '.' . $attribute); + $last_query->addSelect($table.'.'.$attribute); $query->leftJoin($table, $foreign, $other); break; @@ -82,7 +80,7 @@ public function attribute(Builder $query, $relationships, $attribute) $last_query = $model->getQuery(); } - return $table . '.' . $attribute; + return $table.'.'.$attribute; } /** @@ -97,7 +95,5 @@ protected function getColumnByAttribute($attribute) return $col; } } - - return null; } } diff --git a/src/LivewireTablesServiceProvider.php b/src/LivewireTablesServiceProvider.php index fdc279bc1..0d2ded93e 100644 --- a/src/LivewireTablesServiceProvider.php +++ b/src/LivewireTablesServiceProvider.php @@ -9,7 +9,6 @@ */ class LivewireTablesServiceProvider extends ServiceProvider { - /** * Bootstrap the application services. */ diff --git a/tests/TestCase.php b/tests/TestCase.php index 47c30e2be..b4b957422 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,9 +5,7 @@ use Rappasoft\LivewireTables\LivewireTablesServiceProvider; /** - * Class TestCase - * - * @package Rappasoft\LivewireTables\Tests + * Class TestCase. */ class TestCase extends \Orchestra\Testbench\TestCase {