summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Light <samlight1994@gmail.com>2025-09-23 22:54:57 +0100
committerSam Light <samlight1994@gmail.com>2025-09-23 22:54:57 +0100
commit2aca9a441ef48fb66ace8a5bfb9d8b730bc4e925 (patch)
treea3798b6aca1882347e7e55bb1db9249196e0ee73
parent94caf14491860e35eaf07d76e1aea7ee90e1246a (diff)
Initial pint code formatting
-rw-r--r--src/Columns/ButtonColumn.php3
-rw-r--r--src/Columns/Column.php41
-rw-r--r--src/Columns/ElementColumn.php8
-rw-r--r--src/Columns/LinkColumn.php9
-rw-r--r--src/Concerns/WithAttributes.php4
-rw-r--r--src/ServiceProvider.php21
-rw-r--r--src/TableComponent.php64
-rw-r--r--src/Toolbar.php33
-rw-r--r--src/Toolbar/ColumnSelect.php2
-rw-r--r--src/Toolbar/Filter.php15
-rw-r--r--src/Toolbar/Item.php10
-rw-r--r--src/Toolbar/PageSize.php2
-rw-r--r--src/Toolbar/SelectFilter.php9
-rw-r--r--tests/Feature/TableTest.php7
-rw-r--r--tests/TestCase.php12
-rw-r--r--workbench/app/Livewire/CategoriesTable.php3
-rw-r--r--workbench/app/Livewire/OrdersTable.php3
-rw-r--r--workbench/app/Livewire/ProductsTable.php28
-rw-r--r--workbench/app/Livewire/Table.php10
-rw-r--r--workbench/app/Models/Category.php7
-rw-r--r--workbench/app/Models/Product.php12
-rw-r--r--workbench/database/seeders/DatabaseSeeder.php7
-rw-r--r--workbench/routes/web.php9
23 files changed, 149 insertions, 170 deletions
diff --git a/src/Columns/ButtonColumn.php b/src/Columns/ButtonColumn.php
index 2124a37..0c76557 100644
--- a/src/Columns/ButtonColumn.php
+++ b/src/Columns/ButtonColumn.php
@@ -11,8 +11,7 @@ class ButtonColumn extends ElementColumn
protected function getElemAttributes(Model $row): array
{
return parent::getElemAttributes($row) + [
- 'type' => 'button'
+ 'type' => 'button',
];
}
-
}
diff --git a/src/Columns/Column.php b/src/Columns/Column.php
index e260472..0638490 100644
--- a/src/Columns/Column.php
+++ b/src/Columns/Column.php
@@ -2,30 +2,32 @@
namespace Lightscale\LaralightTables\Columns;
-use Lightscale\LaralightTables\TableComponent;
-use Lightscale\LaralightTables\Concerns\Makable;
-
-use Illuminate\Database\Eloquent\Model;
+use Closure;
use Illuminate\Database\Eloquent\Builder;
-use Illuminate\View\ComponentAttributeBag;
+use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\HtmlString;
+use Illuminate\View\ComponentAttributeBag;
+use Lightscale\LaralightTables\Concerns\Makable;
+use Lightscale\LaralightTables\TableComponent;
-use Closure;
-
-class Column {
+class Column
+{
use Makable;
/**
* @var TableComponent<Model>
*/
private TableComponent $table;
+
private bool $showInSelect;
+
private bool $shouldEscape = true;
/**
* @var ?Closure(Model, Column): string
*/
private ?Closure $slotFn = null;
+
private ?Closure $sortFn = null;
/**
@@ -44,7 +46,8 @@ class Column {
/**
* @template TModel of Model
- * @param TableComponent<TModel> $table
+ *
+ * @param TableComponent<TModel> $table
*/
public function setTable(TableComponent $table): void
{
@@ -61,9 +64,10 @@ class Column {
return (string) $row->{$this->name};
}
- public function slot(callable $fn) : static
+ public function slot(callable $fn): static
{
$this->slotFn = Closure::fromCallable($fn);
+
return $this;
}
@@ -72,6 +76,7 @@ class Column {
if ($fn !== null) {
$this->sortFn = Closure::fromCallable($fn);
}
+
return $this;
}
@@ -82,7 +87,8 @@ class Column {
/**
* @template TModel of Model
- * @param Builder<TModel> $query
+ *
+ * @param Builder<TModel> $query
*/
public function applySort(Builder $query, ?string $dir): void
{
@@ -91,26 +97,29 @@ class Column {
}
}
- public function colClass(string $v) : static
+ public function colClass(string $v): static
{
$this->colClass = $v;
+
return $this;
}
- public function getColClass() : ?string
+ public function getColClass(): ?string
{
return $this->colClass;
}
- public function tdAttributes(callable $fn) : static
+ public function tdAttributes(callable $fn): static
{
$this->tdAttributesFn = Closure::fromCallable($fn);
+
return $this;
}
public function showInSelect(bool $show = true): static
{
$this->showInSelect = $show;
+
return $this;
}
@@ -122,6 +131,7 @@ class Column {
public function shouldEscape(bool $v): static
{
$this->shouldEscape = $v;
+
return $this;
}
@@ -133,6 +143,7 @@ class Column {
protected function getContent(Model $row): string
{
$content = $this->slotFn === null ? $this->defaultSlot($row) : ($this->slotFn)($row, $this);
+
return $this->escape($content);
}
@@ -149,7 +160,7 @@ class Column {
$attributes = $this->tdAttributesFn?->call($this, $row) ?? [];
$attributes = (new ComponentAttributeBag($attributes))->toHtml();
$content = $this->getContent($row);
+
return new HtmlString("<td {$attributes}>{$content}</td>");
}
-
}
diff --git a/src/Columns/ElementColumn.php b/src/Columns/ElementColumn.php
index aaac071..a6024e3 100644
--- a/src/Columns/ElementColumn.php
+++ b/src/Columns/ElementColumn.php
@@ -2,15 +2,13 @@
namespace Lightscale\LaralightTables\Columns;
+use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\HtmlString;
use Illuminate\View\ComponentAttributeBag;
-use Closure;
-
abstract class ElementColumn extends Column
{
-
protected string $element;
/**
@@ -18,9 +16,10 @@ abstract class ElementColumn extends Column
*/
private ?Closure $elemAttributesFn = null;
- public function attributes(callable $fn) : static
+ public function attributes(callable $fn): static
{
$this->elemAttributesFn = Closure::fromCallable($fn);
+
return $this;
}
@@ -42,5 +41,4 @@ abstract class ElementColumn extends Column
"<{$this->element} {$attributes}>{$content}</{$this->element}>"
);
}
-
}
diff --git a/src/Columns/LinkColumn.php b/src/Columns/LinkColumn.php
index 35cedcf..ee974df 100644
--- a/src/Columns/LinkColumn.php
+++ b/src/Columns/LinkColumn.php
@@ -2,9 +2,8 @@
namespace Lightscale\LaralightTables\Columns;
-use Illuminate\Database\Eloquent\Model;
-
use Closure;
+use Illuminate\Database\Eloquent\Model;
class LinkColumn extends ElementColumn
{
@@ -15,17 +14,17 @@ class LinkColumn extends ElementColumn
*/
private Closure $urlFn;
- public function url(callable $fn) : static
+ public function url(callable $fn): static
{
$this->urlFn = Closure::fromCallable($fn);
+
return $this;
}
- public function getElemAttributes(Model $row) : array
+ public function getElemAttributes(Model $row): array
{
return parent::getElemAttributes($row) + [
'href' => ($this->urlFn)($row),
];
}
-
}
diff --git a/src/Concerns/WithAttributes.php b/src/Concerns/WithAttributes.php
index 9072145..d97f84a 100644
--- a/src/Concerns/WithAttributes.php
+++ b/src/Concerns/WithAttributes.php
@@ -12,11 +12,12 @@ trait WithAttributes
protected ?array $attributes = null;
/**
- * @param array<string, string> $attributes
+ * @param array<string, string> $attributes
*/
public function attributes(array $attributes): static
{
$this->attributes = $attributes;
+
return $this;
}
@@ -24,5 +25,4 @@ trait WithAttributes
{
return new ComponentAttributeBag($this->attributes ?? []);
}
-
}
diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php
index a509fff..1128218 100644
--- a/src/ServiceProvider.php
+++ b/src/ServiceProvider.php
@@ -2,26 +2,22 @@
namespace Lightscale\LaralightTables;
-use Lightscale\LaralightAssets\Facades\Assets;
-
-use Illuminate\Support\ServiceProvider as ServiceProviderBase;
use Illuminate\Foundation\Console\AboutCommand;
+use Illuminate\Support\ServiceProvider as ServiceProviderBase;
+use Lightscale\LaralightAssets\Facades\Assets;
class ServiceProvider extends ServiceProviderBase
{
- public function register() : void
- {
-
- }
+ public function register(): void {}
- public function boot() : void
+ public function boot(): void
{
- AboutCommand::add('Laralight Tables', fn() => [
- 'Version' => 'dev'
+ AboutCommand::add('Laralight Tables', fn () => [
+ 'Version' => 'dev',
]);
$ns = Service::NAMESPACE;
- $root = __DIR__ . '/..';
+ $root = __DIR__.'/..';
$viewsPath = "{$root}/resources/views";
$assetsUri = "vendor/{$ns}";
$assetsPath = public_path($assetsUri);
@@ -30,7 +26,7 @@ class ServiceProvider extends ServiceProviderBase
$this->publishes([
$viewsPath => resource_path("views/vendor/{$ns}"),
- ], Service::NAMESPACE . '-views');
+ ], Service::NAMESPACE.'-views');
$this->publishes([
"{$root}/public" => $assetsPath,
@@ -38,5 +34,4 @@ class ServiceProvider extends ServiceProviderBase
Assets::registerManifest($ns, "{$assetsPath}/assets-manifest.json", $assetsUri);
}
-
}
diff --git a/src/TableComponent.php b/src/TableComponent.php
index 8e84d50..180d7c4 100644
--- a/src/TableComponent.php
+++ b/src/TableComponent.php
@@ -2,23 +2,19 @@
namespace Lightscale\LaralightTables;
-use Lightscale\LaralightTables\Columns\Column;
-use Lightscale\LaralightTables\Toolbar\Filter;
-use Lightscale\LaralightAssets\Facades\Assets;
-
-use Livewire\Component;
-use Livewire\WithPagination;
-use Livewire\Attributes\Url;
-
-use Illuminate\Pagination\Paginator;
+use Exception;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
-use Illuminate\Support\Str;
+use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
+use Illuminate\Support\Str;
use Illuminate\View\View;
-
-use Exception;
-
+use Lightscale\LaralightAssets\Facades\Assets;
+use Lightscale\LaralightTables\Columns\Column;
+use Lightscale\LaralightTables\Toolbar\Filter;
+use Livewire\Attributes\Url;
+use Livewire\Component;
+use Livewire\WithPagination;
/**
* @template TModel of Model
@@ -34,7 +30,6 @@ abstract class TableComponent extends Component
*/
protected $paginationTheme = 'bootstrap';
-
/**
* @var ?class-string<TModel>
*/
@@ -43,10 +38,13 @@ abstract class TableComponent extends Component
protected int $defaultPageSize = 10;
protected ?string $rootClass = null;
+
protected string $tableClass = 'table';
protected string $tableWrapperComponent = 'laralight-tables::wrapper';
+
protected string $paginationWrapperComponent = 'laralight-tables::wrapper';
+
protected string $toolbarsWrapperComponent = 'laralight-tables::wrapper';
// Properties
@@ -83,14 +81,14 @@ abstract class TableComponent extends Component
protected function setDefaultPageSize(): void
{
- if (!isset($this->pageSize)) {
+ if (! isset($this->pageSize)) {
$this->pageSize = $this->defaultPageSize;
}
}
protected function setDefaultActiveColumns(): void
{
- foreach($this->getColumns() as $column) {
+ foreach ($this->getColumns() as $column) {
$this->activeColumns[] = $column->name;
}
}
@@ -99,8 +97,9 @@ abstract class TableComponent extends Component
{
$search = $this
->getToolbars()
- ->first(fn(Toolbar $tb) => $tb->getSearch() !== null)
+ ->first(fn (Toolbar $tb) => $tb->getSearch() !== null)
?->getSearch();
+
return $search !== null && Str::length($this->search) >= $search->getMinLength();
}
@@ -122,12 +121,10 @@ abstract class TableComponent extends Component
if ($this->orderDirection === 'desc') {
$this->order = null;
$this->orderDirection = null;
- }
- else {
+ } else {
$this->orderDirection = 'desc';
}
- }
- else {
+ } else {
$this->order = $column;
$this->orderDirection = 'asc';
}
@@ -151,24 +148,27 @@ abstract class TableComponent extends Component
*/
protected function getToolbars(): Collection
{
- if (!isset($this->toolbarsCache)) {
+ if (! isset($this->toolbarsCache)) {
$this->toolbarsCache = collect($this->toolbars());
}
+
return $this->toolbarsCache;
}
/**
* @return Builder<TModel>
+ *
* @phpstan-return Builder<TModel>
*/
protected function query(): Builder
{
- if($this->model === null) {
+ if ($this->model === null) {
throw new Exception('Requires $model to be set or query() method to be overridden');
}
/** @var Builder<TModel> */
$query = $this->model::query();
+
return $query;
}
@@ -178,10 +178,9 @@ abstract class TableComponent extends Component
abstract protected function columns(): array;
/**
- * @param Builder<TModel> $builder
- * @param string $search
+ * @param Builder<TModel> $builder
*/
- protected function search(Builder $builder, string $search) : void {}
+ protected function search(Builder $builder, string $search): void {}
/**
* @return Collection<int, Filter>
@@ -189,18 +188,17 @@ abstract class TableComponent extends Component
protected function getFilters(): Collection
{
return $this->getToolbars()
- ->map(fn(Toolbar $toolbar): Collection => $toolbar->getFilters())
+ ->map(fn (Toolbar $toolbar): Collection => $toolbar->getFilters())
->flatten();
}
-
protected function getOrderColumn(): ?Column
{
return ($name = $this->order) === null ? null : $this->getColumns()[$name] ?? null;
}
/**
- * @param Builder<TModel> $query
+ * @param Builder<TModel> $query
*/
protected function applyOrder(Builder $query): void
{
@@ -213,7 +211,7 @@ abstract class TableComponent extends Component
/**
* @return Builder<TModel>
*/
- protected function buildQuery() : Builder
+ protected function buildQuery(): Builder
{
$query = $this->query();
@@ -240,9 +238,9 @@ abstract class TableComponent extends Component
*/
public function getColumns(): Collection
{
- if($this->columnsCache === null) {
+ if ($this->columnsCache === null) {
$this->columnsCache = collect($this->columns())->each(
- fn($c) => $c->setTable($this)
+ fn ($c) => $c->setTable($this)
)->keyBy('name');
}
@@ -253,7 +251,7 @@ abstract class TableComponent extends Component
{
$data = $this->buildQuery()->paginate($this->pageSize);
$allColumns = $this->getColumns();
- $columns = $allColumns->filter(fn($c) => in_array($c->name,$this->activeColumns));
+ $columns = $allColumns->filter(fn ($c) => in_array($c->name, $this->activeColumns));
$toolbars = $this->getToolbars();
Paginator::defaultView('laralight-tables::pagination');
diff --git a/src/Toolbar.php b/src/Toolbar.php
index 80f093b..0a8aaad 100644
--- a/src/Toolbar.php
+++ b/src/Toolbar.php
@@ -2,21 +2,21 @@
namespace Lightscale\LaralightTables;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Collection;
+use Illuminate\View\View;
+use Lightscale\LaralightTables\Concerns\Makable;
+use Lightscale\LaralightTables\Toolbar\Filter as FilterItem;
use Lightscale\LaralightTables\Toolbar\Item as ToolbarItem;
-use Lightscale\LaralightTables\Toolbar\Search as SearchItem;
use Lightscale\LaralightTables\Toolbar\PageSize as PageSizeItem;
-use Lightscale\LaralightTables\Toolbar\Filter as FilterItem;
-use Lightscale\LaralightTables\Concerns\Makable;
-
-use Illuminate\View\View;
-use Illuminate\Support\Collection;
-use Illuminate\Database\Eloquent\Model;
+use Lightscale\LaralightTables\Toolbar\Search as SearchItem;
class Toolbar
{
use Makable;
protected ?SearchItem $searchItem = null;
+
protected ?PageSizeItem $pageSizeItem = null;
/**
@@ -41,12 +41,12 @@ class Toolbar
/**
* @template TModel of Model
- * @param TableComponent<TModel> $table
+ *
+ * @param TableComponent<TModel> $table
*/
public function __construct(
private TableComponent $table
- )
- {
+ ) {
$this->startItems = collect();
$this->midItems = collect();
$this->endItems = collect();
@@ -59,32 +59,32 @@ class Toolbar
if ($item instanceof FilterItem) {
$this->filterItems->push($item);
- }
- else if ($item instanceof PageSizeItem) {
+ } elseif ($item instanceof PageSizeItem) {
$this->pageSizeItem = $item;
- }
- else if ($item instanceof SearchItem) {
+ } elseif ($item instanceof SearchItem) {
$this->searchItem = $item;
}
}
/**
- * @param Collection<int, ToolbarItem> $list
+ * @param Collection<int, ToolbarItem> $list
*/
private function prependItem(Collection $list, ToolbarItem $item): static
{
$this->processItem($item);
$list->prepend($item);
+
return $this;
}
/**
- * @param Collection<int, ToolbarItem> $list
+ * @param Collection<int, ToolbarItem> $list
*/
private function appendItem(Collection $list, ToolbarItem $item): static
{
$this->processItem($item);
$list->push($item);
+
return $this;
}
@@ -152,5 +152,4 @@ class Toolbar
'endItems' => $this->endItems,
]);
}
-
}
diff --git a/src/Toolbar/ColumnSelect.php b/src/Toolbar/ColumnSelect.php
index 9380650..8e173cd 100644
--- a/src/Toolbar/ColumnSelect.php
+++ b/src/Toolbar/ColumnSelect.php
@@ -13,7 +13,7 @@ class ColumnSelect extends Item
return view('laralight-tables::toolbar.column-select', [
'allColumns' => $this->getTable()
->getColumns()
- ->filter(fn($c) => $c->getShowInSelect())
+ ->filter(fn ($c) => $c->getShowInSelect()),
]);
}
}
diff --git a/src/Toolbar/Filter.php b/src/Toolbar/Filter.php
index f6777ce..d444dcf 100644
--- a/src/Toolbar/Filter.php
+++ b/src/Toolbar/Filter.php
@@ -2,10 +2,9 @@
namespace Lightscale\LaralightTables\Toolbar;
-use Illuminate\Database\Eloquent\Model;
-use Illuminate\Database\Eloquent\Builder;
-
use Closure;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Model;
abstract class Filter extends Item
{
@@ -19,6 +18,7 @@ abstract class Filter extends Item
public function label(string $v): static
{
$this->label = $v;
+
return $this;
}
@@ -29,23 +29,24 @@ abstract class Filter extends Item
public function filter(callable $fn): static
{
- $this->filterCallback = Closure::fromCallable($fn);;
+ $this->filterCallback = Closure::fromCallable($fn);
+
return $this;
}
/**
* @template TModel of Model
- * @param Builder<TModel> $query
+ *
+ * @param Builder<TModel> $query
*/
public function applyFilter(Builder $query): void
{
if ($this->filterCallback !== null) {
$value = $this->getTable()->filters[$this->key] ?? null;
- if (!empty($value)) {
+ if (! empty($value)) {
($this->filterCallback)($query, $value);
}
}
}
-
}
diff --git a/src/Toolbar/Item.php b/src/Toolbar/Item.php
index e161fb9..1b4d1fb 100644
--- a/src/Toolbar/Item.php
+++ b/src/Toolbar/Item.php
@@ -2,13 +2,12 @@
namespace Lightscale\LaralightTables\Toolbar;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\HtmlString;
+use Illuminate\View\View;
+use Lightscale\LaralightTables\Concerns\Makable;
use Lightscale\LaralightTables\TableComponent;
use Lightscale\LaralightTables\Toolbar;
-use Lightscale\LaralightTables\Concerns\Makable;
-
-use Illuminate\View\View;
-use Illuminate\Support\HtmlString;
-use Illuminate\Database\Eloquent\Model;
abstract class Item
{
@@ -35,5 +34,4 @@ abstract class Item
}
abstract public function render(): View|HtmlString|string|null;
-
}
diff --git a/src/Toolbar/PageSize.php b/src/Toolbar/PageSize.php
index 79234a8..71049ba 100644
--- a/src/Toolbar/PageSize.php
+++ b/src/Toolbar/PageSize.php
@@ -7,7 +7,7 @@ use Illuminate\View\View;
class PageSize extends Item
{
/**
- * @param array<int> $pageSizes
+ * @param array<int> $pageSizes
*/
public function __construct(
private array $pageSizes = [10, 25, 50],
diff --git a/src/Toolbar/SelectFilter.php b/src/Toolbar/SelectFilter.php
index 7adc47a..d9c6118 100644
--- a/src/Toolbar/SelectFilter.php
+++ b/src/Toolbar/SelectFilter.php
@@ -2,9 +2,8 @@
namespace Lightscale\LaralightTables\Toolbar;
-use Lightscale\LaralightTables\Concerns\WithAttributes;
-
use Illuminate\View\View;
+use Lightscale\LaralightTables\Concerns\WithAttributes;
class SelectFilter extends Filter
{
@@ -14,20 +13,23 @@ class SelectFilter extends Filter
* @var iterable<string, string>
*/
protected iterable $options;
+
protected ?string $placeholder = null;
public function placeholder(?string $v): static
{
$this->placeholder = $v;
+
return $this;
}
/**
- * @param iterable<string, string> $options
+ * @param iterable<string, string> $options
*/
public function options(iterable $options): static
{
$this->options = $options;
+
return $this;
}
@@ -42,5 +44,4 @@ class SelectFilter extends Filter
'attributes' => $this->getAttributes(),
]);
}
-
}
diff --git a/tests/Feature/TableTest.php b/tests/Feature/TableTest.php
index cd22fb6..8dc327c 100644
--- a/tests/Feature/TableTest.php
+++ b/tests/Feature/TableTest.php
@@ -1,11 +1,10 @@
<?php
-use Workbench\App\Livewire\ProductsTable;
-
use Livewire\Livewire;
+use Workbench\App\Livewire\ProductsTable;
-describe('products table', function() {
- it('does render', function() {
+describe('products table', function () {
+ it('does render', function () {
Livewire::test(ProductsTable::class)
->assertSeeHtml('<table')
->assertSeeHtml('<thead>')
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 03ebdcd..9b6f0ad 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -2,16 +2,14 @@
namespace Lightscale\LaralightTables\Tests;
+use Illuminate\Foundation\Testing\RefreshDatabase;
use Lightscale\LaralightTables\ServiceProvider;
-
-use Workbench\Database\Seeders\DatabaseSeeder;
-
-use Orchestra\Testbench\TestCase as Orchestra;
+use Livewire\LivewireServiceProvider;
use Orchestra\Testbench\Concerns\WithWorkbench;
+use Orchestra\Testbench\TestCase as Orchestra;
+use Workbench\Database\Seeders\DatabaseSeeder;
use function Orchestra\Testbench\workbench_path;
-use Illuminate\Foundation\Testing\RefreshDatabase;
-use Livewire\LivewireServiceProvider;
class TestCase extends Orchestra
{
@@ -19,6 +17,7 @@ class TestCase extends Orchestra
use WithWorkbench;
protected $seed = true;
+
protected $seeder = DatabaseSeeder::class;
protected function getPackageProviders($app)
@@ -35,5 +34,4 @@ class TestCase extends Orchestra
workbench_path('database/migrations')
);
}
-
}
diff --git a/workbench/app/Livewire/CategoriesTable.php b/workbench/app/Livewire/CategoriesTable.php
index efc5760..0fedd71 100644
--- a/workbench/app/Livewire/CategoriesTable.php
+++ b/workbench/app/Livewire/CategoriesTable.php
@@ -2,9 +2,8 @@
namespace Workbench\App\Livewire;
-use Workbench\App\Models\Category;
-
use Lightscale\LaralightTables\Columns\Column;
+use Workbench\App\Models\Category;
/**
* @extends Table<Category>
diff --git a/workbench/app/Livewire/OrdersTable.php b/workbench/app/Livewire/OrdersTable.php
index adc0ddc..e42be1d 100644
--- a/workbench/app/Livewire/OrdersTable.php
+++ b/workbench/app/Livewire/OrdersTable.php
@@ -2,9 +2,8 @@
namespace Workbench\App\Livewire;
-use Workbench\App\Models\Product;
-
use Lightscale\LaralightTables\Columns\Column;
+use Workbench\App\Models\Product;
/**
* @extends Table<Product>
diff --git a/workbench/app/Livewire/ProductsTable.php b/workbench/app/Livewire/ProductsTable.php
index 204c2e2..6a52cc5 100644
--- a/workbench/app/Livewire/ProductsTable.php
+++ b/workbench/app/Livewire/ProductsTable.php
@@ -2,17 +2,15 @@
namespace Workbench\App\Livewire;
-use Workbench\App\Models\Product;
-use Workbench\App\Models\Category;
-
+use Illuminate\Database\Eloquent\Builder;
use Lightscale\LaralightTables\Columns\Column;
use Lightscale\LaralightTables\Toolbar;
-use Lightscale\LaralightTables\Toolbar\Search;
-use Lightscale\LaralightTables\Toolbar\PageSize;
use Lightscale\LaralightTables\Toolbar\ColumnSelect;
+use Lightscale\LaralightTables\Toolbar\PageSize;
+use Lightscale\LaralightTables\Toolbar\Search;
use Lightscale\LaralightTables\Toolbar\SelectFilter;
-
-use Illuminate\Database\Eloquent\Builder;
+use Workbench\App\Models\Category;
+use Workbench\App\Models\Product;
/**
* @extends Table<Product>
@@ -27,9 +25,9 @@ class ProductsTable extends Table
->placeholder(__('Filter category'))
->options(Category::pluck('name', 'id'))
->filter(
- fn(Builder $q, string $value) => $q->whereHas(
+ fn (Builder $q, string $value) => $q->whereHas(
'category',
- fn(Builder $q) => $q->where('id', $value)
+ fn (Builder $q) => $q->where('id', $value)
)
);
@@ -57,16 +55,16 @@ class ProductsTable extends Table
{
return [
Column::make('id', 'ID')
- ->sortable(fn(Builder $q, string $dir) => $q->orderBy('id', $dir)),
+ ->sortable(fn (Builder $q, string $dir) => $q->orderBy('id', $dir)),
Column::make('name', 'Name')
- ->sortable(fn(Builder $q, string $dir) => $q->orderBy('name', $dir)),
+ ->sortable(fn (Builder $q, string $dir) => $q->orderBy('name', $dir)),
Column::make('category_name', 'Category')
- ->slot(fn($r) => $r->category->name),
+ ->slot(fn ($r) => $r->category->name),
Column::make('price', 'Price')
- ->sortable(fn(Builder $q, string $dir) => $q->orderBy('price', $dir))
- ->slot(fn($r, $c) => "£{$r->{$c->name}}"),
+ ->sortable(fn (Builder $q, string $dir) => $q->orderBy('price', $dir))
+ ->slot(fn ($r, $c) => "£{$r->{$c->name}}"),
Column::make('stock', 'Stock')
- ->sortable(fn(Builder $q, string $dir) => $q->orderBy('stock', $dir)),
+ ->sortable(fn (Builder $q, string $dir) => $q->orderBy('stock', $dir)),
];
}
}
diff --git a/workbench/app/Livewire/Table.php b/workbench/app/Livewire/Table.php
index 6a91a24..da8b66c 100644
--- a/workbench/app/Livewire/Table.php
+++ b/workbench/app/Livewire/Table.php
@@ -2,16 +2,12 @@
namespace Workbench\App\Livewire;
-use Lightscale\LaralightTables\TableComponent;
-use Lightscale\LaralightTables\Toolbar;
-
use Illuminate\Database\Eloquent\Model;
+use Lightscale\LaralightTables\TableComponent;
/**
* @template TModel of Model
+ *
* @extends TableComponent<TModel>
*/
-abstract class Table extends TableComponent
-{
-
-}
+abstract class Table extends TableComponent {}
diff --git a/workbench/app/Models/Category.php b/workbench/app/Models/Category.php
index 39e2edd..8e30c31 100644
--- a/workbench/app/Models/Category.php
+++ b/workbench/app/Models/Category.php
@@ -2,21 +2,18 @@
namespace Workbench\App\Models;
-use Workbench\Database\Factories\CategoryFactory;
-
use Illuminate\Database\Eloquent\Factories\HasFactory;
-use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\HasMany;
+use Workbench\Database\Factories\CategoryFactory;
class Category extends Model
{
-
/**
* @use HasFactory<CategoryFactory>
*/
use HasFactory;
-
/**
* @return CategoryFactory<static>
*/
diff --git a/workbench/app/Models/Product.php b/workbench/app/Models/Product.php
index cf9892e..a44cb03 100644
--- a/workbench/app/Models/Product.php
+++ b/workbench/app/Models/Product.php
@@ -2,16 +2,14 @@
namespace Workbench\App\Models;
-use Workbench\Database\Factories\ProductFactory;
-
+use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
-use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Workbench\Database\Factories\ProductFactory;
class Product extends Model
{
-
/**
* @use HasFactory<ProductFactory>
*/
@@ -26,14 +24,14 @@ class Product extends Model
}
/**
- * @param Builder<static> $q
+ * @param Builder<static> $q
*/
public function scopeSearch(Builder $q, string $s): void
{
$s = "%{$s}%";
- $q->where(fn(Builder $q) => (
+ $q->where(fn (Builder $q) => (
$q->orWhere('name', 'like', $s)
- ->orWhere('description', 'like', $s)
+ ->orWhere('description', 'like', $s)
));
}
diff --git a/workbench/database/seeders/DatabaseSeeder.php b/workbench/database/seeders/DatabaseSeeder.php
index 877fd97..9b7e84a 100644
--- a/workbench/database/seeders/DatabaseSeeder.php
+++ b/workbench/database/seeders/DatabaseSeeder.php
@@ -2,10 +2,9 @@
namespace Workbench\Database\Seeders;
-use Workbench\App\Models\Product;
-use Workbench\App\Models\Category;
-
use Illuminate\Database\Seeder;
+use Workbench\App\Models\Category;
+use Workbench\App\Models\Product;
class DatabaseSeeder extends Seeder
{
@@ -17,7 +16,7 @@ class DatabaseSeeder extends Seeder
$categories = Category::factory()->count(10)->create();
Product::factory()
- ->state(fn() => ['category_id' => $categories->random()->id])
+ ->state(fn () => ['category_id' => $categories->random()->id])
->count(104)
->create();
}
diff --git a/workbench/routes/web.php b/workbench/routes/web.php
index 11635a1..facdc67 100644
--- a/workbench/routes/web.php
+++ b/workbench/routes/web.php
@@ -1,12 +1,9 @@
<?php
use Illuminate\Support\Facades\Route;
-
-use Workbench\App\Livewire\{
- ProductsTable,
- CategoriesTable,
- OrdersTable,
-};
+use Workbench\App\Livewire\CategoriesTable;
+use Workbench\App\Livewire\OrdersTable;
+use Workbench\App\Livewire\ProductsTable;
Route::get('/products', ProductsTable::class)->name('products');
Route::get('/categories', CategoriesTable::class)->name('categories');