PHPackages                             marshmallow/button-field - 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. [Admin Panels](/categories/admin)
4. /
5. marshmallow/button-field

ActiveLibrary[Admin Panels](/categories/admin)

marshmallow/button-field
========================

A Laravel Nova field.

v1.7.0(2y ago)02.1k↓43.8%MITVuePHP ^7.3|^8.0

Since Jul 11Pushed 3w ago1 watchersCompare

[ Source](https://github.com/marshmallow-packages/button-field)[ Packagist](https://packagist.org/packages/marshmallow/button-field)[ RSS](/packages/marshmallow-button-field/feed)WikiDiscussions main Synced today

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

[![alt text](https://camo.githubusercontent.com/f5450f299f5713ce2f04dd5a1ba7ce9960ed4568b3574e4c4ee3cddc75477253/68747470733a2f2f6d617273686d616c6c6f772e6465762f63646e2f6d656469612f6c6f676f2d7265642d3233377834362e706e67 "marshmallow.")](https://camo.githubusercontent.com/f5450f299f5713ce2f04dd5a1ba7ce9960ed4568b3574e4c4ee3cddc75477253/68747470733a2f2f6d617273686d616c6c6f772e6465762f63646e2f6d656469612f6c6f676f2d7265642d3233377834362e706e67)

Nova Button Package
===================

[](#nova-button-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/91c72235c3261160beead44ec4eccf1bc9037af293ca46569b0d09255d46e7dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617273686d616c6c6f772f627574746f6e2d6669656c642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marshmallow/button-field)[![Total Downloads](https://camo.githubusercontent.com/a7852da4c9dbfc47b1dece5327ba901c01b4f1f6c982b96d9579098bd490fa9c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617273686d616c6c6f772f627574746f6e2d6669656c642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marshmallow/button-field)[![Issues](https://camo.githubusercontent.com/d66cb42f499e16e38f334af7d8424f86ff9f4f571845c9c5d8e991c6601fa831/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6d617273686d616c6c6f772d7061636b616765732f627574746f6e2d6669656c643f7374796c653d666c61742d737175617265)](https://github.com/marshmallow-packages/button-field/issues)[![License](https://camo.githubusercontent.com/f2c416738a93dcd4701c626dbae03b659442fda20c2d34fa403039756fcbebab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d617273686d616c6c6f772f627574746f6e2d6669656c643f7374796c653d666c61742d737175617265)](https://github.com/marshmallow-packages/button-field)

A Laravel Nova field that renders a button on your resource — link out, trigger a download, run a Nova action, or execute custom code on click.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require marshmallow/button-field
```

Usage
-----

[](#usage)

Add the field to your Nova resource. By default the field resolves its link from the column you pass to `make()`. As with any Nova field, you can return your own value with `resolveUsing()`.

```
use Marshmallow\ButtonField\ButtonField;

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

The field is hidden on the create form and never writes back to the model (its `fillUsing` is a no-op), so it is safe to use as a pure action/link field.

Methods
-------

[](#methods)

### button()

[](#button)

When you call the `button` method, this will return a default Laravel Nova Button. This should have the same styling as the Update and Update &amp; Continue Editing buttons in your Nova installation. This method is called by default so this behaviour should be available out of the box.

```
$button_field->button();
```

### target()

[](#target)

You can call the `target` method to change the behaviour of your button.

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

### download()

[](#download)

When you call the `download` method, the styling of the button will change. It will be a smaller button with a download icon next to it. We will also add the “download” tag to the button so the browser knows you want to download something. You can see an example of this in the screenshot at the top of this page.

```
$button_field->download();
```

### setButtonText()

[](#setbuttontext)

The default text of the created button is “Download”. You can change this by calling the `setButtonText` method.

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

### text()

[](#text)

Call the `text` method to render the button as a plain text-style button instead of the default Nova button. This is the type required by the `onClick` method below.

```
$button_field->text();
```

### icon()

[](#icon)

Add an icon to the button by passing an icon name to the `icon` method.

```
$button_field->icon('download');
```

### visibleWhen()

[](#visiblewhen)

You can use the `visibleWhen` method if a button should only be visible when a condition applies.

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

### onClick()

[](#onclick)

You can use the `onClick` method to run any kind of action to your model. This is a very powerfull method that allows you to do anything! This currently only works on the text type button so we must set it to `text()`. Please check the example below how to implement this on your Nova Resource.

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

Now we need to create an action class that will be run when the button is clicked. You can create this anywhere you like. This could be the location app/Actions/Nova/SendInvoice.php. In this file you create a class that implements the OnClickInterface interface. You need to create 3 methods in this class. Please check the example below.

```
