nervure / laravel
Laravel integration for nervure: animated SVG charts, maps and dashboards in Blade and Livewire.
Package info
pkg:composer/nervure/laravel
Requires
- php: >=8.2
- illuminate/support: ^11.0|^12.0
- illuminate/view: ^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Animated SVG charts, maps and dashboards of nervure in Blade and Livewire: a Blade component, a @nervureScripts directive and a chart builder.
Documentation: https://nervurejs.github.io/guide/symfony-laravel
Install
composer require nervure/laravel
php artisan vendor:publish --tag=nervure-config # optional
PHP 8.2+, Laravel 11 or 12. The service provider and the Nervure facade are discovered.
Configure
// config/nervure.php return [ 'theme' => env('NERVURE_THEME', 'auto'), // light, dark or auto 'locale' => null, // the language of the page by default 'animation' => true, // true, false, or 'visible': plays when the chart comes into view 'toolbar' => false, // export button (SVG, PNG, CSV) 'zoom' => false, 'height' => 300, // pixels, or any CSS length 'assets' => env('NERVURE_ASSETS', 'cdn'), // cdn or vite 'version' => '0.14.0', // nervure version loaded from the CDN 'cdn' => 'https://cdn.jsdelivr.net/npm/nervure@{version}/cdn/nervure.min.js', ];
Load nervure
With the CDN (default), once in your layout:
@nervureScripts
@nervureScripts('nonce') adds a CSP nonce; with Vite's Vite::useCspNonce() the nonce is added by itself.
With Vite, set NERVURE_ASSETS=vite, then:
npm install nervure
// resources/js/app.js import 'nervure/element'; import '../../vendor/nervure/laravel/resources/js/nervure-blade.js';
Use
use BenMacha\LaravelNervure\Facades\Nervure; $spec = Nervure::xy() ->categories(['Jan', 'Feb', 'Mar']) ->series('Orders', [120, 180, 150], kind: 'bar') ->format(currency: 'EUR');
<x-nervure-chart :spec="$spec" height="300" theme="dark" toolbar />
A spec is a PHP array or a builder. The builder knows xy, pie, gauge, kpi, map and timeline; Nervure::of('sankey', [...]) and ->with('field', $value) reach every other type and field. The specs of the 89 chart types: https://nervurejs.github.io/charts/
Other attributes (class, id, wire:key) go on the wrapper of the chart.
Livewire 3
Nothing to add: the drawing sits in a wire:ignore element, and its spec on the wrapper. When the component renders again, Livewire updates the spec and the chart draws the new data.
final class Sales extends Component { public string $year = '2026'; public function render() { return view('livewire.sales', [ 'spec' => Nervure::xy()->categories($this->months())->series('Sales', $this->sales()), ]); } }
<div> <select wire:model.live="year">…</select> <x-nervure-chart :spec="$spec" wire:key="sales-chart" /> </div>
Events
The chart element fires ready with the chart:
document.querySelector('nervure-chart').addEventListener('ready', (event) => event.detail.toPNG());
License
MIT, Ali Ben Macha.