diff --git a/docs/customization/action-buttons.md b/docs/customization/action-buttons.md index 3fc3b642f6..f482b0d986 100644 --- a/docs/customization/action-buttons.md +++ b/docs/customization/action-buttons.md @@ -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 +id > 10; +} +``` + ## Mass Actions Mass actions are called for multiple instances of a model. diff --git a/resources/views/bread/partials/actions.blade.php b/resources/views/bread/partials/actions.blade.php index de93ee1ce3..3ec0007e50 100644 --- a/resources/views/bread/partials/actions.blade.php +++ b/resources/views/bread/partials/actions.blade.php @@ -5,9 +5,11 @@ $action = new $class($dataType, $data); @endphp @can ($action->getPolicy(), $data) - convertAttributesToHtml() !!}> - - + @if ($action->shouldActionDisplayOnRow($data)) + convertAttributesToHtml() !!}> + + + @endif @endcan @elseif (method_exists($action, 'massAction'))
diff --git a/src/Actions/AbstractAction.php b/src/Actions/AbstractAction.php index 10172cd44b..c3f8d74db0 100644 --- a/src/Actions/AbstractAction.php +++ b/src/Actions/AbstractAction.php @@ -50,4 +50,9 @@ public function shouldActionDisplayOnDataType() { return $this->dataType->name === $this->getDataType() || $this->getDataType() === null; } + + public function shouldActionDisplayOnRow($row) + { + return true; + } }