tonysm / Turbo Laravel
Labels
Projects that are alternatives of or similar to Turbo Laravel
This package gives you a set of conventions to make the most out of Hotwire in Laravel (inspired by the turbo-rails gem). There is a companion application that shows how to use the package and its conventions in your application.
Installation
You may install the package via composer:
composer require tonysm/turbo-laravel
You may publish the asset files with:
php artisan turbo:install
You may also use Turbo Laravel with Jetstream if you use the Livewire stack. If you want to do so, you may want to publish the assets using the --jet
flag:
php artisan turbo:install --jet
The turbo:install command will require and publish a couple JS files to your application. By default, it will add @hotwired/turbo
to your package.json
file and publish another custom HTML tag to integrate Turbo with Laravel Echo. With the --jet
flag, it will also add a couple bridge libs needed to make sure you can use Hotwire with Jetstream, these are:
- Alpine Turbo Bridge, needed so Alpine.js works nicely; and
-
Livewire Turbo Plugin needed so Livewire works nicely. This one will be added to your Jetstream layouts as script tags fetching from a CDN (both
app.blade.php
andguest.blade.php
)
You may also optionally install Stimulus on top of this all by passing --stimulus
flag to the turbo:install
command. It's optional because we can either use Alpine.js or Stimulus (or both /shrug):
php artisan turbo:install --jet --stimulus
The package ships with a middleware that applies some conventions on your redirects, specially around how failed validations are redirected automatically by Laravel. To read more about this, check out the Conventions section documentation. You may add the middleware to the "web" route group on your HTTP Kernel, like so:
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
protected $middlewareGroups = [
'web' => [
// ...
\Tonysm\TurboLaravel\Http\Middleware\TurboMiddleware::class,
],
];
}
Keep reading the documentation to have a full picture on how you can make the most out of the technique.
Documentation
It's highly recommended reading the Turbo Handbook. Out of everything Turbo provides, it's the Turbo Streams that benefits the most from a tight integration with Laravel. We can generate Turbo Stream from your models and either return them from HTTP responses or broadcast your model changes to all users over WebSockets using Laravel Echo.
Checkout the documentation to see everything that is possible and then try the package.
-
Overview
- Conventions
- Notes on Turbo Drive and Turbo Frames
-
Turbo Streams
- Turbo Stream Request Macro
- Turbo Stream Responses
- Override Model's Partial Names and Partial Data
- Override Model's Resource Name and DOM ID
- Custom Turbo Stream View
- Override Turbo Streams Views
- Turbo Streams and Laravel Echo
- Broadcasting Turbo Streams on Model Changes
- Override Turbo Stream Broadcasting Channel
- The Broadcasts Trait for Models
- Listening to Turbo Stream Broadcasts
- Broadcasting Turbo Streams to Other Users Only
- Validation Response Redirects
- Turbo Native
- Testing Helpers
Closing Notes
Try the package out. Use your Browser's DevTools to inspect the responses. You will be able to spot every single Turbo Frame and Turbo Stream happening.
"The proof of the pudding is in the eating."
Make something awesome!
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Drop me an email at [email protected] if you want to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.