PHPackages                             almirhodzic/nova-toggle-5 - 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. almirhodzic/nova-toggle-5

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

almirhodzic/nova-toggle-5
=========================

A Laravel Nova 5 toggle field that allows quick boolean updates directly from the index view.

v1.3.1(2mo ago)31.9k—0%1MITVuePHP ^8.2

Since Nov 5Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/almirhodzic/nova-toggle-5)[ Packagist](https://packagist.org/packages/almirhodzic/nova-toggle-5)[ Docs](https://novafront.dev)[ RSS](/packages/almirhodzic-nova-toggle-5/feed)WikiDiscussions main Synced yesterday

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)Security (1)

Laravel Nova 5 Toggle Field
===========================

[](#laravel-nova-5-toggle-field)

This Laravel Nova 5 Toggle Field removes the detour into the edit page and lets you flip booleans directly in the index. Fewer clicks, less context switching, smoother workflow.

[![Laravel Nova 5 Toggle Field](https://camo.githubusercontent.com/80e62cf0ecb6f41b203c150a8e0bbf7fb464195e11c9351c01549176b74c7ba5/68747470733a2f2f6e6f766166726f6e742e6465762f696d616765732f746f67676c652f6e6f76612d746f67676c652d352d646f63732e706e673f7631)](https://camo.githubusercontent.com/80e62cf0ecb6f41b203c150a8e0bbf7fb464195e11c9351c01549176b74c7ba5/68747470733a2f2f6e6f766166726f6e742e6465762f696d616765732f746f67676c652f6e6f76612d746f67676c652d352d646f63732e706e673f7631)

 [![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667) [![Nova 5](https://camo.githubusercontent.com/6f6002f969c93e87fe56d2c514adce7d7d20edb8278216e15ae105b764ca8d8c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4e6f76612d352e782d626c75652e737667)](https://camo.githubusercontent.com/6f6002f969c93e87fe56d2c514adce7d7d20edb8278216e15ae105b764ca8d8c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4e6f76612d352e782d626c75652e737667) [![PHP 8.2+](https://camo.githubusercontent.com/5fe05c705bf034839bda7651781e4d0a9d42f4a840478ca5e343873a0361bb89/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322b2d626c75652e737667)](https://camo.githubusercontent.com/5fe05c705bf034839bda7651781e4d0a9d42f4a840478ca5e343873a0361bb89/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322b2d626c75652e737667) [![Downloads](https://camo.githubusercontent.com/58afea3b6458e64a77796c3750a2de68dc50a755e330a7cd09006eb54481881c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6d6972686f647a69632f6e6f76612d746f67676c652d352e737667)](https://camo.githubusercontent.com/58afea3b6458e64a77796c3750a2de68dc50a755e330a7cd09006eb54481881c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6d6972686f647a69632f6e6f76612d746f67676c652d352e737667)

Features
--------

[](#features)

- Quick toggle directly from index view
- Customizable colors for light and dark mode
- Built-in readonly and visibility controls
- Optional help text for different views
- Custom ON/OFF labels with color customization
- Optional toast notification control
- Customizable toast message labels
- Filter support for index views
- Logs the update action in Nova's action events
- Vue 3 Composition API
- Full dark mode support

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel Nova 5.x

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

[](#installation)

```
composer require almirhodzic/nova-toggle-5
```

The service provider will be automatically registered.

Upgrading from 1.2 to 1.3
-------------------------

[](#upgrading-from-12-to-13)

Version 1.3.0 contains a security fix that changes how the toggle endpoint is authorized. For most installations the upgrade is a drop-in: just run `composer update almirhodzic/nova-toggle-5`.

What changed:

- The toggle endpoint is now protected by Nova's own `nova:api` middleware. Only users who pass the `viewNova` gate can reach it.
- The controller additionally checks the resource's `authorizedToUpdate` policy and only allows writes to attributes that are actually exposed as a `Toggle`field on the resource.
- The `config/nova-toggle-5.php` file (with its `guards` option) has been removed. If you previously published it, you can delete it — it is no longer read.

If you were relying on the old `guards` config to grant toggle access to users that do **not** pass the `viewNova` gate, make sure those users are now either allowed by the gate or no longer need toggle access.

Basic Usage
-----------

[](#basic-usage)

```
use AlmirHodzic\NovaToggle5\Toggle;

public function fields(NovaRequest $request)
{
    return [
        Toggle::make('Active', 'is_active'),
    ];
}
```

Configuration
-------------

[](#configuration)

### Colors

[](#colors)

#### Toggle Background Colors

[](#toggle-background-colors)

```
Toggle::make('Active', 'is_active')
    ->onColor('#00d5be', '#009689')  // Light mode, Dark mode
    ->offColor('#e5e5e5', '#323f57');
```

#### Bullet Colors

[](#bullet-colors)

```
Toggle::make('Active', 'is_active')
    ->onBullet('white')           // Same for both modes
    ->offBullet('white', 'grey'); // Light mode, Dark mode
```

### Labels

[](#labels)

#### Custom ON/OFF Text

[](#custom-onoff-text)

```
Toggle::make('Active', 'is_active')
    ->valueLabelText('ON', 'OFF');  // ON label, OFF label
```

#### Label Colors

[](#label-colors)

```
Toggle::make('Active', 'is_active')
    ->valueLabelText('ON', 'OFF')
    ->valueLabelOnColors('#ffffff')              // ON label color
    ->valueLabelOffColors('#a1a1a1', '#737373'); // OFF label colors (light, dark)
```

### Toast Notifications

[](#toast-notifications)

#### Custom Toast Label

[](#custom-toast-label)

By default, the toast message uses the resource's `name`, `label`, `title`, or the resource's singular label. You can customize which model attribute to use:

```
Toggle::make('Show', 'show')
    ->toastLabelKey('question'); // Uses $model->question instead of default
```

**Default fallback order:** `name` → `label` → `title` → resource singular label

#### Disable Toast Notifications

[](#disable-toast-notifications)

```
Toggle::make('Active', 'is_active')
    ->toastShow(false); // No toast notification on toggle
```

### Filtering

[](#filtering)

To make your toggle field filterable in the index view, you need to create a custom filter.

#### Step 1: Create a Filter

[](#step-1-create-a-filter)

```
php artisan nova:filter IsActiveFilter
```

#### Step 2: Implement the Filter

[](#step-2-implement-the-filter)

```
