<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digital-creative / nova-detached-actions example snippets
namespace App\Nova\Actions;
use DigitalCreative\DetachedActions\DetachedAction;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Laravel\Nova\Fields\ActionFields;
class ExportUsers extends DetachedAction
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* Get the displayable label of the button.
*
* @return string
*/
public function label()
{
return __('Export Users');
}
/**
* Perform the action.
*
* @param ActionFields $fields
*
* @return mixed
*/
public function handle(ActionFields $fields)
{
// Do work to export records
return DetachedAction::message('It worked!');
}
/**
* Get the fields available on the action.
*
* @return array
*/
public function fields()
{
return [];
}
}
...
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function actions(Request $request)
{
return [
new App\Nova\Actions\ExportUsers
];
}
...
...
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function actions(Request $request)
{
return [
(new DownloadExcel)->withHeadings()->askForWriterType()->withMeta([
'detachedAction' => true,
'label' => 'Export'
])->confirmButtonText('Export'),
];
}
...
bash
php artisan nova:action ExportUsers
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.