Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Html/Options/HasColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public function columns(array $columns): static

$this->collection->push(new Column($attributes));
} else {
$this->collection->push($value);

// Only add the column if it is authorized, otherwise ignore it.
if ($value->isAuthorized()) {
$this->collection->push($value);
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,19 @@ public function it_has_editors()
]);
$this->assertCount(2, $builder->getEditors());
}

#[Test]
public function it_ignores_unauthorized_columns(): void
{
$builder = $this->getHtmlBuilder();

$builder->columns([
Column::makeIf(false)
->title('unauthorized_column'),

Column::make('authorized_column'),
]);

$this->assertCount(1, $builder->getColumns());
}
}
Loading