Docs Getting Started
Installation
Turbo Laravel can be installed with Cargo:
cargo add turbo-laravel
The package is called turbo-laravel, but your code imports it as turbo, as in use turbo::stream;.
Next, register the service provider in src/app.rs:
use laravel::Application;
Application::configure()
.with_providers(|providers| {
providers.add(turbo::TurboServiceProvider);
});
The provider adds the Turbo middleware to the web group, registers the template helpers and the Hotwire Native routes, and, in the local and testing environments, the turbo:install and turbo:skills commands.
The frontend
After registering the provider, run the turbo:install command:
laravel turbo:install
It sets up your frontend for Turbo:
- installs
@hotwired/turbo,laravel-echoandpusher-jswith the package manager your lockfile names (npm, pnpm, yarn or bun); - writes the
turbo-echo-stream-sourcecustom element, which connects broadcasts to Turbo, toresources/js/elements/; - writes a
resources/js/echo.jsconfigured for Reverb, and adds theVITE_REVERB_*variables to your.envfiles; - imports Turbo, Echo and the element from your entry file,
resources/js/app.{ts,tsx,js,jsx}; - adds the CSRF meta tag to
resources/views/app.html; - publishes the agent skills.
Running it again changes nothing, so it's safe to run on an existing app. It takes a few flags:
| Flag | Effect |
|---|---|
--without-broadcasting |
Leaves out Echo, for apps that don't broadcast streams. |
--without-skills |
Doesn't publish the agent skills. |
--force |
Replaces the stream source element if it exists. |
--no-install |
Doesn't install the npm packages. |
If your app already configures Echo, the command leaves that setup alone. The stream source element needs window.Echo, so make sure your setup sets it.
Setting up the frontend by hand
If you'd rather set things up yourself, install the packages:
npm install @hotwired/turbo laravel-echo pusher-js
Copy turbo-echo-stream-source.js to resources/js/elements/ and echo.js to resources/js/, and import them from your entry file:
// resources/js/app.js
import '@hotwired/turbo'
import './echo'
import './elements/turbo-echo-stream-source'
Then add the CSRF meta tag to your layout.
Agent skills
Turbo Laravel ships Agent Skills that teach coding agents how to build with Turbo in a Laravel Rust app. turbo:install publishes them, and you may publish them on their own:
laravel turbo:skills
The command writes the skills to .agents/skills/turbo-*, next to the skills your app came with, and adds a short Turbo Laravel section to your AGENTS.md. The skills read their detailed references from the installed crate, so they always match your version. If your app has no AGENTS.md, the command says so, and you may point your agent's instructions at the skills yourself.
The package manages these files: run laravel turbo:skills again after updating the crate with cargo update, and don't edit them by hand. Write your own skill for notes about your app.
Configuration
Turbo Laravel reads two environment variables:
| Variable | Default | Description |
|---|---|---|
TURBO_NATIVE_ROUTES |
true |
Registers the Hotwire Native historical location routes. |
TURBO_FRAME_REDIRECTS |
true |
Sends failed validations inside a Turbo Frame to the form's page. See Validation Response. |
You may also change them in src/app.rs:
use laravel::Application;
Application::configure()
.with_config(|config, _| {
config.section_mut::<turbo::TurboConfig>().native_routes = false;
});