Skip to content

Commit

Permalink
add action column ⚡
Browse files Browse the repository at this point in the history
  • Loading branch information
rizkhal committed Feb 28, 2022
1 parent e848649 commit 0a2f1cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: ["https://trakteer.id/rizkhal", "https://www.buymeacoffee.com/rizkhal"]
6 changes: 6 additions & 0 deletions src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 12 additions & 3 deletions src/Inertable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ 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
*
* @return array
*/
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());
}

/**
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 0a2f1cf

Please sign in to comment.