PHP code example of datomatic / nova-detached-actions
1. Go to this page and download the library: Download datomatic/nova-detached-actions 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/ */
datomatic / nova-detached-actions example snippets
namespace App\Nova\Actions;
use Datomatic\Nova\Tools\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;
public function name(): string
{
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 \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function actions(NovaRequest $request)
{
return [
new App\Nova\Actions\ExportUsers // or App\Nova\Actions\ExportUsers::make()
];
}
public static function additionalInformation(Request $request)
{
return [
'visibleActionsLimit' => 2
];
}
return [
(new ImportUsers)->extraClasses('bg-primary-500 text-white hover:black')
];
return [
(new ImportUsers)->icon('add')
];
return [
(new ImportUsers)->icon('upload')->iconClasses('mr-3 -ml-2')
];
/** @return array<int,string> */
public function handleRequest(ActionRequest $request): array
{
dispatch(new GenerateTicketReport($request->resolveFields()));
return DetachedAction::message('Nice job!');
}
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.