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. marshmallow/button-field

ActiveLibrary

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

A Laravel Nova field.

v1.7.0(1y ago)01.9k↓30%MITVuePHP ^7.3|^8.0

Since Jul 11Pushed 1y 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 1mo ago

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

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

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

[](#nova-button-package)

[![Version](https://camo.githubusercontent.com/4bd432553aa3a61e4b6773617433137eeae66d254a3b5a080f38ae9de3e8525f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617273686d616c6c6f772f627574746f6e2d6669656c64)](https://github.com/marshmallow-packages/button-field)[![Issues](https://camo.githubusercontent.com/690eca4852b728798cd4fac4a44661f17093ad5263d91c1068d9298c99973bf8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6d617273686d616c6c6f772d7061636b616765732f627574746f6e2d6669656c64)](https://github.com/marshmallow-packages/button-field)[![Code Coverage](https://camo.githubusercontent.com/a47a770765f8c7b5776c024ff602bfc3f3686ba8be5317b3d0c320c715df42c1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d73756363657373)](https://github.com/marshmallow-packages/button-field)[![Licence](https://camo.githubusercontent.com/10fbb00270768715c889099165f8f5a40f4bed09953690e4e231f5c8ef46bd3d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d617273686d616c6c6f772d7061636b616765732f627574746f6e2d6669656c64)](https://github.com/marshmallow-packages/button-field)

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

[](#installation)

You can install the package via composer:

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

Usage
-----

[](#usage)

By default this package will resolve the link from the column you provide when calling the make method. By calling the `resolveUsing` method you can return your own generated link to the button.

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

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');
```

### 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.

```
