diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..42232a2 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: ["https://trakteer.id/rizkhal", "https://www.buymeacoffee.com/rizkhal"] \ No newline at end of file diff --git a/src/Column.php b/src/Column.php index c499408..7674936 100644 --- a/src/Column.php +++ b/src/Column.php @@ -50,8 +50,14 @@ public static function blank(): Column return new static(null, null); } + public static function action(): Column + { + return new static('action', null); + } + public function checkbox(): Column { + $this->column = 'checkbox'; $this->checkbox = true; return $this; diff --git a/src/Inertable.php b/src/Inertable.php index 3071764..e5a91fe 100644 --- a/src/Inertable.php +++ b/src/Inertable.php @@ -19,6 +19,15 @@ abstract class Inertable implements WithQuery, WithColumn WithPerPage, WithSorting; + public function columnsMerged(): array + { + if (method_exists($this, 'getKey')) { + return array_merge([Column::make($this->getKey())], $this->columns()); + } + + return array_merge([Column::make('id')], $this->columns()); + } + /** * Get searhable columns * @@ -26,7 +35,7 @@ abstract class Inertable implements WithQuery, WithColumn */ public function getSearchableColumns(): array { - return array_filter($this->columns(), fn (Column $column): bool => $column->isSearchable()); + return array_filter($this->columnsMerged(), fn (Column $column): bool => $column->isSearchable()); } /** @@ -37,7 +46,7 @@ public function getSearchableColumns(): array */ public function getColumn(string|null $column): object { - return collect($this->columns())->where('column', $column)->first(); + return collect($this->columnsMerged())->where('column', $column)->first(); } /** @@ -67,7 +76,7 @@ private function through(Model $model): array { $items = []; - foreach ($this->columns() as $column) { + foreach ($this->columnsMerged() as $column) { if (ColumnAttributes::hasRelation($column->column)) { if (ColumnAttributes::hasMultipleRelation($column->column)) { if ($this->getColumn($column->column)->hasFormatCallback()) {