PHP code example of sietse85 / nova-button

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

    

sietse85 / nova-button example snippets


use Sietse85\NovaButton\Button;

public function fields(Request $request)
{
    return [
        ID::make('ID', 'id')->sortable(),
        Text::make('Name', 'name'),
        Button::make('Notify'),
    ];
}

Button::make('Cancel Account')->confirm('Are you sure?'),
Button::make('Cancel Account')->confirm('Confirmation', 'Are you sure you want to cancel your account?'),
Button::make('Cancel Account')->confirm('Confirmation', 'Are you sure you want to cancel your account?', 'Cancel'),

Button::make('Notify')->reload()

Button::make('Send mail')->action(SendConfirmationMail::class)

Button::make('Notify', 'notify-some-user')

Button::make('Notify')->event(App\Events\NotifyRequested::class)

Button::make('Notify')->title('Button title')

Button::make('Notify')->label('Button label')

Button::make('Notify')->indexName('Actions')

Button::make('Activate')->visible($this->is_active === false),
Button::make('Deactivate')->visible($this->is_active === true),

Button::make('Notify')->visible($request->user()->can('notifyUser', $this))

Button::make('Notify')->showOnCreating()->showOnUpdating()

Button::make('Notify')->disabled()
Button::make('Notify')->disabled($this->is_complete === false)

Button::make('Notify')
    ->loadingText('Sending...')
    ->successText('Sent!')
    ->errorText('Something went wrong...')

Button::make('Text')->index(App\Nova\User::class)
Button::make('Text')->detail(App\Nova\User::class, $this->user_id)
Button::make('Text')->create(App\Nova\User::class)
Button::make('Text')->edit(App\Nova\User::class, $this->user_id)
Button::make('Text')->lens(App\Nova\User::class, 'users-without-confirmation')

Button::make('Text')
    ->index(App\Nova\Order::class)
    ->withFilters([
        App\Nova\Filters\UserOrders::class => $this->user_id,
        App\Nova\Filters\OrderStatus::class => 'active',
    ])

Button::make('Text')->link('https://nova.laravel.com')
Button::make('Text')->link('https://nova.laravel.com', '_self')

// One class
Button::make('Notify')->classes(['some-class'])

// Or multiple classes
Button::make('Notify')->classes(['some-class', 'another-class'])

// One class
Button::make('Notify')->confirm('sure?')->modalClasses(['some-class'])

// Or multiple classes
Button::make('Notify')->confirm('sure?')->modalClasses(['some-class', 'another-class'])

Button::make('Delete')->style('danger')



namespace App\Nova\Lenses;

class UsersWithoutConfirmation extends Lens
{
    public static function query(LensRequest $request, $query)
    {
        return $query
            ->select(['users.id', 'users.name'])
            ->whereNull('email_verified_at');
    }

    public function fields(Request $request)
    {
        return [
            ID::make('ID', 'id'),
            Text::make('Name', 'name'),
            Button::make('Mark As Confirmed'),
        ];
    }
}



namespace App\Listeners;

use Sietse85\NovaButton\Events\ButtonClick;

class ConfirmUser
{
    public function handle(ButtonClick $event)
    {
        if ($event->key == 'mark-as-confirmed') {
            $event->resource->email_verified_at = now();
            $event->resource->save();
        }
    }
}
bash
php artisan vendor:publish --tag="nova-button-config"