Skip to content

Commit

Permalink
Action buttons on per-row base (#5355)
Browse files Browse the repository at this point in the history
* Action buttons on per-row base

* Action buttons on per-row base
  • Loading branch information
emptynick committed Aug 31, 2021
1 parent 39be175 commit 5a4a4af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
11 changes: 11 additions & 0 deletions docs/customization/action-buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public function shouldActionDisplayOnDataType()
}
```

If you want to show your action-button on a per-row-base, simply implement a method `shouldActionDisplayOnRow($row)` and add your condition(s)

```php
<?php

public function shouldActionDisplayOnRow($row)
{
return $row->id > 10;
}
```

## Mass Actions

Mass actions are called for multiple instances of a model.
Expand Down
8 changes: 5 additions & 3 deletions resources/views/bread/partials/actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
$action = new $class($dataType, $data);
@endphp
@can ($action->getPolicy(), $data)
<a href="{{ $action->getRoute($dataType->name) }}" title="{{ $action->getTitle() }}" {!! $action->convertAttributesToHtml() !!}>
<i class="{{ $action->getIcon() }}"></i> <span class="hidden-xs hidden-sm">{{ $action->getTitle() }}</span>
</a>
@if ($action->shouldActionDisplayOnRow($data))
<a href="{{ $action->getRoute($dataType->name) }}" title="{{ $action->getTitle() }}" {!! $action->convertAttributesToHtml() !!}>
<i class="{{ $action->getIcon() }}"></i> <span class="hidden-xs hidden-sm">{{ $action->getTitle() }}</span>
</a>
@endif
@endcan
@elseif (method_exists($action, 'massAction'))
<form method="post" action="{{ route('voyager.'.$dataType->slug.'.action') }}" style="display:inline">
Expand Down
5 changes: 5 additions & 0 deletions src/Actions/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public function shouldActionDisplayOnDataType()
{
return $this->dataType->name === $this->getDataType() || $this->getDataType() === null;
}

public function shouldActionDisplayOnRow($row)
{
return true;
}
}

0 comments on commit 5a4a4af

Please sign in to comment.