diff --git a/README.md b/README.md index 2ac073d..b68b81f 100644 --- a/README.md +++ b/README.md @@ -69,3 +69,23 @@ class UserTable extends Inertable } } ``` + +Add hidden response + +```php +protected $hiddens = [ + 'office' +]; +``` + +The response will include `office` object in response to inertable props. + +Hidden response also accept relatoin, for example if you have `HasMany` relation from user to posts + +```php +protected $hiddens = [ + 'user.posts' +]; +``` + +That's will return hidden user posts inside inertable props. diff --git a/composer.json b/composer.json index 7126498..1584e77 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": "^8.0", "illuminate/support": "^8.62|^9.0.0", - "inertiajs/inertia-laravel": "^0.6.2" + "inertiajs/inertia-laravel": "^0.6.3" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.1", diff --git a/src/Commands/MakeDatatableCommand.php b/src/Commands/MakeDatatableCommand.php new file mode 100644 index 0000000..f8253f6 --- /dev/null +++ b/src/Commands/MakeDatatableCommand.php @@ -0,0 +1,45 @@ +getKey())], $this->columns()); } + if (property_exists($this, 'hiddens')) { + $tmp = []; + + foreach ($this->hiddens as $key => $value) { + $tmp[] = Column::make($value); + } + + return array_merge([Column::make('id')], $tmp, $this->columns()); + } + return array_merge([Column::make('id')], $this->columns()); } @@ -77,7 +88,7 @@ public function applyInertable(Request $request): LengthAwarePaginator $query = $this->applySearchFilter($request, $query); - return $query->paginate($this->perPage(), ['*'], $request->get('table') ?: 'inertable')->withQueryString()->through(fn ($model) => $this->through($model)); + return $query->paginate($this->perPage())->withQueryString()->through(fn ($model) => $this->through($model)); } /** diff --git a/src/Column.php b/src/View/Column.php similarity index 94% rename from src/Column.php rename to src/View/Column.php index 1aab5ff..08df86b 100644 --- a/src/Column.php +++ b/src/View/Column.php @@ -1,6 +1,6 @@ formatCallback; } + + public function nullable() + { + $this->na = true; + + return $this; + } }