PHPackages                             dillingham/nova-button - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dillingham/nova-button

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dillingham/nova-button
======================

Nova button package

1.0.11(5y ago)2651.5M↑71%33[16 issues](https://github.com/dillingham/nova-button/issues)[18 PRs](https://github.com/dillingham/nova-button/pulls)MITPHP

Since Jan 6Pushed 2y ago5 watchersCompare

[ Source](https://github.com/dillingham/nova-button)[ Packagist](https://packagist.org/packages/dillingham/nova-button)[ RSS](/packages/dillingham-nova-button/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (31)Used By (0)

Nova Button
-----------

[](#nova-button)

Thanks for everyone who used this package and contributed.

I haven't used Nova in many years so I'm unable to maintain this.

I'm so glad to see active forks though!

-
-

---

[![Latest Version on Github](https://camo.githubusercontent.com/711e3815ddba5d8c628bbfcd006885a07444c6899c38ddd05613b692173bd92e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f64696c6c696e6768616d2f6e6f76612d627574746f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dillingham/nova-button)[![Total Downloads](https://camo.githubusercontent.com/71c32af1366467b2362a476571eeea86ba39df9c328e1f3147d75646cb1e0f3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64696c6c696e6768616d2f6e6f76612d627574746f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dillingham/nova-button) [![Twitter Follow](https://camo.githubusercontent.com/216e5f4cbf47232ed1715f38b25a38e08b5ae59d14e7c2d6f168e38d04985500/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f666f6c6c6f772f7369725f627269616e5f643f636f6c6f723d253233316461316631266c6162656c3d54776974746572266c6f676f3d253233316461316631266c6f676f436f6c6f723d253233316461316631267374796c653d666c61742d737175617265)](https://twitter.com/sir_brian_d)

Nova package for rendering buttons on index, detail and lens views.

Use buttons to trigger backend events, navigate nova routes or visit links.

[![nova-button](https://user-images.githubusercontent.com/29180903/50742708-dffeb600-11dc-11e9-9eed-36f42166c7c4.png)](https://user-images.githubusercontent.com/29180903/50742708-dffeb600-11dc-11e9-9eed-36f42166c7c4.png)

### Installation

[](#installation)

```
composer require dillingham/nova-button
```

### Usage

[](#usage)

```
use NovaButton\Button;
```

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

Quick links: [Button Styles](https://github.com/dillingham/nova-button#button-styles) | [Event text / style](https://github.com/dillingham/nova-button#button-state) | [Navigation](https://github.com/dillingham/nova-button#button-navigation) | [CSS classes](https://github.com/dillingham/nova-button#button-classes) | [Lens example](https://github.com/dillingham/nova-button#example)

---

### Backend events

[](#backend-events)

By default, clicking the button will trigger a backend event via ajax.

Default event: `NovaButton\Events\ButtonClick`

The event will receive the resource model it was triggered from &amp; the key

- `$event->resource` = `model`
- `$event->key` = `"notify"`

Adding a custom key

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

Adding a custom event

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

You register listeners in your EventServiceProvider

### Nova Routes

[](#nova-routes)

You can also choose to navigate any of the Nova routes

```
Button::make('Text')->route('vuejs-route-name', ['id' => 1])
Button::make('Text')->index('App\Nova\User')
Button::make('Text')->detail('App\Nova\User', $this->user_id)
Button::make('Text')->create('App\Nova\User')
Button::make('Text')->edit('App\Nova\User', $this->user_id)
Button::make('Text')->lens('App\Nova\User', 'users-without-confirmation')
```

You can also enable a resource's filters

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

### Links

[](#links)

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

### Visiblity

[](#visiblity)

You will likely want to show or hide buttons depending on model values

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

Also [field authorization](https://nova.laravel.com/docs/1.0/resources/authorization.html#fields) via canSee() &amp; [showing / hiding fields](https://nova.laravel.com/docs/1.0/resources/fields.html#showing-hiding-fields) hideFromIndex(), etc

### Reload

[](#reload)

After events are triggered, reload the page.

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

If you click many buttons, reloading will wait for all buttons to finish.

If an error occurs, it will not reload the page.

### Confirm

[](#confirm)

You can require a confirmation for descructive actions

```
Button::make('Cancel Account')->confirm('Are you sure?'),
Button::make('Cancel Account')->confirm('title', 'content'),
```

### Button state

[](#button-state)

When using events, you want visual feedback for the end user.

This is especially useful for long running listeners.

```
Button::make('Remind User')->loadingText('Sending..')->successText('Sent!')
```

EventTextStyleloading`loadingText('Loading..')``loadingStyle('grey-outline')`success`successText('Done!')``successStyle('success')`error`errorText('Failed')``errorStyle('danger')`Defaults defined in the `nova-button` config. Add methods when you want to change for specific resources

### Button styles

[](#button-styles)

This package makes use of [tailwind-css](https://tailwindcss.com) classes / default: `link`

```
Button::make('Confirm')->style('primary')
```

FillOutlineLinkprimaryprimary-outlineprimary-linksuccesssuccess-outlinesuccess-linkdangerdanger-outlinedanger-linkwarningwarning-outlinewarning-linkinfoinfo-outlineinfo-linkgreygrey-outlinegrey-linkEach key adds classes from the `nova-button` config

```
'primary' => 'btn btn-default btn-primary'
```

### Style config

[](#style-config)

Publish the nova-button config to add / edit [available styles &amp; defaults](https://github.com/dillingham/nova-button/blob/master/config/nova-button.php)

```
php artisan vendor:publish --tag=nova-button -- force

```

### Button classes

[](#button-classes)

You can also add classes manually

```
Button::make('Refund')->classes('some-class')
```

Also able to style the following css classes

```
.nova-button
.nova-button-{resource-name}
.nova-button-success
.nova-button-error
.nova-button-loading
```

---

Example
=======

[](#example)

Use [lenses](https://nova.laravel.com/docs/1.0/lenses/defining-lenses.html) with buttons for a very focused user experience

[![lens-button](https://user-images.githubusercontent.com/29180903/50742642-31f30c00-11dc-11e9-96c2-e0534e963aed.png)](https://user-images.githubusercontent.com/29180903/50742642-31f30c00-11dc-11e9-96c2-e0534e963aed.png)

```
