PHP code example of marshmallow / button-field

1. Go to this page and download the library: Download marshmallow/button-field 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/ */

    

marshmallow / button-field example snippets


use Marshmallow\ButtonField\ButtonField;
ButtonField::make('Certificate')->resolveUsing(function () {
    return '___YOUR_LINK_GOES_HERE___';
}),

$button_field->button();

$button_field->target('_blank'); // DEFAULT
$button_field->target('_self');

$button_field->download();

$button_field->setButtonText('Go to user profile');

$button_field->visibleWhen(function() {
    // Call methods on your resource
    return $this->certificateIsAvailable();
}, __('Certificate is not generated yet'));

ButtonField::make(__('Send invoice'))
	->text()
	->setButtonText(__('Send invoice'))
	->onClick(SendInvoice::class),



namespace App\Actions\Nova;

use Exception;
use Illuminate\Database\Eloquent\Model;
use Marshmallow\ButtonField\Contracts\OnClickInterface;

class SendInvoice implements OnClickInterface
{
    public function execute(Model $model): void
    {
        // Run your code!
    }

    public function success(): string
    {
        return __('Invoice is end successfully');
    }

    public function error(Exception $exception): string
    {
        return __('Something went wrong: :exception', [
            'exception' => $exception->getMessage(),
        ]);
    }
}

ButtonField::make(__('Nova Action'))
    ->action(
        action: new \App\Nova\Actions\DemoAction,
        resourceId: $this->resource->id,
        label: 'Run the demo dude!'
    ),