Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit 5a4a4af

Browse files
authored
Action buttons on per-row base (#5355)
* Action buttons on per-row base * Action buttons on per-row base
1 parent 39be175 commit 5a4a4af

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

docs/customization/action-buttons.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ public function shouldActionDisplayOnDataType()
8181
}
8282
```
8383

84+
If you want to show your action-button on a per-row-base, simply implement a method `shouldActionDisplayOnRow($row)` and add your condition(s)
85+
86+
```php
87+
<?php
88+
89+
public function shouldActionDisplayOnRow($row)
90+
{
91+
return $row->id > 10;
92+
}
93+
```
94+
8495
## Mass Actions
8596

8697
Mass actions are called for multiple instances of a model.

resources/views/bread/partials/actions.blade.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
$action = new $class($dataType, $data);
66
@endphp
77
@can ($action->getPolicy(), $data)
8-
<a href="{{ $action->getRoute($dataType->name) }}" title="{{ $action->getTitle() }}" {!! $action->convertAttributesToHtml() !!}>
9-
<i class="{{ $action->getIcon() }}"></i> <span class="hidden-xs hidden-sm">{{ $action->getTitle() }}</span>
10-
</a>
8+
@if ($action->shouldActionDisplayOnRow($data))
9+
<a href="{{ $action->getRoute($dataType->name) }}" title="{{ $action->getTitle() }}" {!! $action->convertAttributesToHtml() !!}>
10+
<i class="{{ $action->getIcon() }}"></i> <span class="hidden-xs hidden-sm">{{ $action->getTitle() }}</span>
11+
</a>
12+
@endif
1113
@endcan
1214
@elseif (method_exists($action, 'massAction'))
1315
<form method="post" action="{{ route('voyager.'.$dataType->slug.'.action') }}" style="display:inline">

src/Actions/AbstractAction.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ public function shouldActionDisplayOnDataType()
5050
{
5151
return $this->dataType->name === $this->getDataType() || $this->getDataType() === null;
5252
}
53+
54+
public function shouldActionDisplayOnRow($row)
55+
{
56+
return true;
57+
}
5358
}

0 commit comments

Comments
 (0)