{"id":36375066,"url":"https://github.com/almirhodzic/nova-toggle-5","last_synced_at":"2026-01-11T14:46:55.461Z","repository":{"id":321856028,"uuid":"1087135910","full_name":"almirhodzic/nova-toggle-5","owner":"almirhodzic","description":"Laravel Nova 5 Toggle Field","archived":false,"fork":false,"pushed_at":"2025-11-23T11:31:02.000Z","size":92,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-23T13:12:11.583Z","etag":null,"topics":["laravel","laravel-package","nova-extension","nova-tool","nova5","tailwindcss-v4","toggle","typescript","vue3"],"latest_commit_sha":null,"homepage":"https://novafront.dev","language":"Vue","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/almirhodzic.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-31T12:39:02.000Z","updated_at":"2025-11-23T11:31:06.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/almirhodzic/nova-toggle-5","commit_stats":null,"previous_names":["almirhodzic/nova-toggle","almirhodzic/nova-toggle-5"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/almirhodzic/nova-toggle-5","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almirhodzic%2Fnova-toggle-5","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almirhodzic%2Fnova-toggle-5/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almirhodzic%2Fnova-toggle-5/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almirhodzic%2Fnova-toggle-5/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/almirhodzic","download_url":"https://codeload.github.com/almirhodzic/nova-toggle-5/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almirhodzic%2Fnova-toggle-5/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28308389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:27:22.573Z","status":"ssl_error","status_checked_at":"2026-01-11T14:27:21.986Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-package","nova-extension","nova-tool","nova5","tailwindcss-v4","toggle","typescript","vue3"],"created_at":"2026-01-11T14:46:54.802Z","updated_at":"2026-01-11T14:46:55.452Z","avatar_url":"https://github.com/almirhodzic.png","language":"Vue","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Nova 5 Toggle Field\n\nThis 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.\n\n![Laravel Nova 5 Toggle Field](https://novafront.dev/images/toggle/nova-toggle-5-docs.png?v1)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/License-MIT-blue.svg\" alt=\"License: MIT\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Nova-5.x-blue.svg\" alt=\"Nova 5\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/PHP-8.2+-blue.svg\" alt=\"PHP 8.2+\" /\u003e\n  \u003cimg src=\"https://img.shields.io/packagist/dt/almirhodzic/nova-toggle-5.svg\" alt=\"Downloads\" /\u003e\n\u003c/p\u003e\n\n## Features\n\n- Quick toggle directly from index view\n- Customizable colors for light and dark mode\n- Built-in readonly and visibility controls\n- Optional help text for different views\n- Custom ON/OFF labels with color customization\n- Optional toast notification control\n- Customizable toast message labels\n- Filter support for index views\n- Logs the update action in Nova's action events\n- Vue 3 Composition API\n- Full dark mode support\n\n## Requirements\n\n- PHP 8.2+\n- Laravel Nova 5.x\n\n## Installation\n\n```bash\ncomposer require almirhodzic/nova-toggle-5\n```\n\nThe service provider will be automatically registered.\n\n## Basic Usage\n\n```php\nuse AlmirHodzic\\NovaToggle5\\Toggle;\n\npublic function fields(NovaRequest $request)\n{\n    return [\n        Toggle::make('Active', 'is_active'),\n    ];\n}\n```\n\n## Configuration\n\n### Colors\n\n#### Toggle Background Colors\n\n```php\nToggle::make('Active', 'is_active')\n    -\u003eonColor('#00d5be', '#009689')  // Light mode, Dark mode\n    -\u003eoffColor('#e5e5e5', '#323f57');\n```\n\n#### Bullet Colors\n\n```php\nToggle::make('Active', 'is_active')\n    -\u003eonBullet('white')           // Same for both modes\n    -\u003eoffBullet('white', 'grey'); // Light mode, Dark mode\n```\n\n### Labels\n\n#### Custom ON/OFF Text\n\n```php\nToggle::make('Active', 'is_active')\n    -\u003evalueLabelText('ON', 'OFF');  // ON label, OFF label\n```\n\n#### Label Colors\n\n```php\nToggle::make('Active', 'is_active')\n    -\u003evalueLabelText('ON', 'OFF')\n    -\u003evalueLabelOnColors('#ffffff')              // ON label color\n    -\u003evalueLabelOffColors('#a1a1a1', '#737373'); // OFF label colors (light, dark)\n```\n\n### Toast Notifications\n\n#### Custom Toast Label\n\nBy 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:\n\n```php\nToggle::make('Show', 'show')\n    -\u003etoastLabelKey('question'); // Uses $model-\u003equestion instead of default\n```\n\n**Default fallback order:** `name` → `label` → `title` → resource singular label\n\n#### Disable Toast Notifications\n\n```php\nToggle::make('Active', 'is_active')\n    -\u003etoastShow(false); // No toast notification on toggle\n```\n\n### Filtering\n\nTo make your toggle field filterable in the index view, you need to create a custom filter.\n\n#### Step 1: Create a Filter\n\n```bash\nphp artisan nova:filter IsActiveFilter\n```\n\n#### Step 2: Implement the Filter\n\n```php\n\u003c?php\n\nnamespace App\\Nova\\Filters;\n\nuse Illuminate\\Contracts\\Database\\Eloquent\\Builder;\nuse Laravel\\Nova\\Filters\\Filter;\nuse Laravel\\Nova\\Http\\Requests\\NovaRequest;\n\nclass IsActiveFilter extends Filter\n{\n    public $name = 'Active Status';\n\n    public $component = 'select-filter';\n\n    public function apply(NovaRequest $request, Builder $query, mixed $value): Builder\n    {\n        if ($value === 'active') {\n            return $query-\u003ewhere('is_active', true);\n        }\n\n        if ($value === 'inactive') {\n            return $query-\u003ewhere('is_active', false);\n        }\n\n        return $query;\n    }\n\n    public function options(NovaRequest $request): array\n    {\n        return [\n            'Active' =\u003e 'active',\n            'Inactive' =\u003e 'inactive',\n        ];\n    }\n}\n```\n\n#### Step 3: Register the Filter in Your Resource\n\n```php\nuse App\\Nova\\Filters\\IsActiveFilter;\n\npublic function filters(NovaRequest $request): array\n{\n    return [\n        new IsActiveFilter,\n    ];\n}\n```\n\n#### Alternative: Boolean Filter (Checkboxes)\n\nIf you prefer checkboxes instead of a dropdown:\n\n```php\n\u003c?php\n\nnamespace App\\Nova\\Filters;\n\nuse Illuminate\\Contracts\\Database\\Eloquent\\Builder;\nuse Laravel\\Nova\\Filters\\BooleanFilter;\nuse Laravel\\Nova\\Http\\Requests\\NovaRequest;\n\nclass IsActiveFilter extends BooleanFilter\n{\n    public $name = 'Active Status';\n\n    public function apply(NovaRequest $request, Builder $query, mixed $value): Builder\n    {\n        if (isset($value['active'])) {\n            return $query-\u003ewhere('is_active', $value['active']);\n        }\n\n        if (isset($value['inactive'])) {\n            return $query-\u003ewhere('is_active', !$value['inactive']);\n        }\n\n        return $query;\n    }\n\n    public function options(NovaRequest $request): array\n    {\n        return [\n            'Active' =\u003e 'active',\n            'Inactive' =\u003e 'inactive',\n        ];\n    }\n}\n```\n\nNow use\n\n```php\nToggle::make('Active', 'is_active')\n    -\u003efilterable()\n    ...\n```\n\n### Help Text\n\nAdd contextual help text for different views:\n\n```php\nToggle::make('Active', 'is_active')\n    -\u003ehelpOnIndex('Toggle to activate/deactivate')\n    -\u003ehelpOnForm('Enable this option to activate the feature')\n    -\u003ehelpOnDetail('Current activation status');\n```\n\n### Visibility \u0026 Access Control\n\n#### Hide Based on Condition\n\n```php\nToggle::make('Active', 'is_active')\n    -\u003ehideWhen(function ($request, $resource) {\n        return $resource-\u003estatus === 'archived';\n    });\n```\n\n#### Readonly Based on Condition\n\n```php\nToggle::make('Active', 'is_active')\n    -\u003ereadonlyWhen(function ($request, $resource) {\n        return !$request-\u003euser()-\u003eisAdmin();\n    });\n```\n\n#### Guard-Based Access Control\n\nBy default, the toggle checks authentication guards defined in your config. Create a config file:\n\n```php\n// config/nova-toggle-5.php\nreturn [\n    'guards' =\u003e ['web', 'admin'],\n];\n```\n\n## Complete Example\n\n```php\nuse AlmirHodzic\\NovaToggle5\\Toggle;\nuse App\\Nova\\Filters\\IsActiveFilter;\n\npublic function fields(NovaRequest $request)\n{\n    return [\n        ID::make()-\u003esortable(),\n\n        Text::make('Name'),\n\n        Toggle::make('Active', 'is_active')\n            -\u003efilterable()\n            -\u003eonColor('#10b981', '#059669')\n            -\u003eoffColor('#ef4444', '#dc2626')\n            -\u003eonBullet('#ffffff')\n            -\u003eoffBullet('#ffffff')\n            -\u003evalueLabelText('ON', 'OFF')\n            -\u003evalueLabelOnColors('#ffffff')\n            -\u003evalueLabelOffColors('#fecaca', '#fca5a5')\n            -\u003ehelpOnIndex('Click to toggle status')\n            -\u003ehelpOnForm('Enable to make this item visible')\n            -\u003etoastShow(true)\n            -\u003ereadonlyWhen(function ($request, $resource) {\n                return !$request-\u003euser()-\u003ecan('edit', $resource);\n            }),\n\n        Toggle::make('Featured', 'is_featured')\n            -\u003eonColor('#f59e0b')\n            -\u003eoffColor('#6b7280')\n            -\u003evalueLabelText('★', '☆')\n            -\u003etoastShow(false)\n            -\u003ehideWhen(function ($request, $resource) {\n                return !$resource-\u003eis_active;\n            }),\n\n        Toggle::make('Show FAQ', 'show')\n            -\u003etoastLabelKey('question') // Uses $faq-\u003equestion for toast message\n            -\u003ehelpOnIndex('Toggle visibility'),\n    ];\n}\n\npublic function filters(NovaRequest $request): array\n{\n    return [\n        new IsActiveFilter,\n    ];\n}\n```\n\n## API Reference\n\n### Methods\n\n| Method                  | Parameters                                           | Description                            |\n| ----------------------- | ---------------------------------------------------- | -------------------------------------- |\n| `onColor()`             | `string $light, ?string $dark = null`                | Background color when ON               |\n| `offColor()`            | `string $light, ?string $dark = null`                | Background color when OFF              |\n| `onBullet()`            | `string $light, ?string $dark = null`                | Bullet color when ON                   |\n| `offBullet()`           | `string $light, ?string $dark = null`                | Bullet color when OFF                  |\n| `valueLabelText()`      | `?string $onLabel = 'ON', ?string $offLabel = 'OFF'` | Custom label text                      |\n| `valueLabelOnColors()`  | `string $light, ?string $dark = null`                | ON label color                         |\n| `valueLabelOffColors()` | `string $light, ?string $dark = null`                | OFF label color                        |\n| `toastShow()`           | `bool $show = true`                                  | Show/hide toast notification on toggle |\n| `toastLabelKey()`       | `string $key`                                        | Model attribute to use for toast label |\n| `hideWhen()`            | `callable $callback`                                 | Hide field based on condition          |\n| `readonlyWhen()`        | `callable $callback`                                 | Make readonly based on condition       |\n| `helpOnIndex()`         | `string $text`                                       | Help text on index view                |\n| `helpOnForm()`          | `string $text`                                       | Help text on form view                 |\n| `helpOnDetail()`        | `string $text`                                       | Help text on detail view               |\n\n### Default Colors\n\n| State          | Light Mode | Dark Mode |\n| -------------- | ---------- | --------- |\n| ON Background  | `#00d5be`  | `#009689` |\n| OFF Background | `#e5e5e5`  | `#323f57` |\n| ON Bullet      | `#ffffff`  | `#ffffff` |\n| OFF Bullet     | `#ffffff`  | `#ffffff` |\n| ON Label       | `#ffffff`  | `#ffffff` |\n| OFF Label      | `#a1a1a1`  | `#737373` |\n\n### Default Behavior\n\n| Option          | Default Value                                                          |\n| --------------- | ---------------------------------------------------------------------- |\n| `toastShow`     | `true`                                                                 |\n| `toastLabelKey` | `null` (uses fallback: name → label → title → resource singular label) |\n\n## Bug or Issues\n\nFound a Bug or Issue? Please report here: [GitHub Issues](https://github.com/almirhodzic/nova-toggle-5/issues)  \nWe appreciate your feedback to help improve this package.\n\n## Support\n\n- [Issues](https://github.com/almirhodzic/nova-toggle-5/issues)\n- [Source Code](https://github.com/almirhodzic/nova-toggle-5)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## Credits\n\n- [Almir Hodzic](https://frontbyte.ch)\n- [All Contributors](../../contributors)\n\n---\n\nBy [Frontbyte](https://frontbyte.ch)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falmirhodzic%2Fnova-toggle-5","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falmirhodzic%2Fnova-toggle-5","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falmirhodzic%2Fnova-toggle-5/lists"}