PHP code example of pavloniym / nova-action-buttons
1. Go to this page and download the library: Download pavloniym/nova-action-buttons library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pavloniym / nova-action-buttons example snippets
use Pavloniym\ActionButtons\ActionButton;
public function fields(Request $request)
{
return [
// ... Nova default fields
ActionButton::make('') // Name in resource table column
->icon('lightning-bolt') // heroicon name ->icon('lightning-bolt')
->iconHtml('<svg></svg>') // Svg (or html) icon
->iconUrl('https://img.com/icon.png') // Url of icon
->text('Refresh') // Title (optional)
->tooltip('Magic tooltip here') // Tooltip text (optional). If not provided, it will default to the action name.
->styles([]) // Custom css styles (optional)
->classes([]) // Custom css classes (optional)
->action(new RefreshAction, $this->resource->id) // Provide action instance and resource id
->asToolbarButton(), // Display as row toolbar button (optional)
// ... Nova default fields
];
}
use Pavloniym\ActionButtons\ActionButton;
public function fields(Request $request)
{
return [
// ... Nova default fields
ActionButtons::make()->collection([
ActionButton::make('')->action(),
ActionButton::make('')->action(),
ActionButton::make('')->action(),
])
// ... Nova default fields
];
}
class RefreshAction extends Action
{
private Torrent $torrent
/**
* @param Torrent $torrent
*/
public function __construct(Torrent $torrent)
{
$this->torrent = $torrent;
}
/**
* Get the fields available on the action.
*
* @param NovaRequest $request
* @return array|null
*/
public function fields(NovaRequest $request): ?array
{
// $request is empty if action is called from index row (or inline)
// so use instance injected to action constructor
$torrent = (fn(): ?Torrent => $request?->selectedResources()?->first())();
$torrent = $torrent ?? $this->torrent;
if ($torrent) {
return [
File::make('File')->creationRules(['