Laravel Turbo is a powerful framework designed to enhance the development of modern web applications. It focuses on creating responsive, interactive applications with minimal effort by combining server-side rendering with client-side interactivity. This approach allows developers to build full-stack applications more efficiently, leveraging the strengths of both backend and frontend technologies.
Key Features
- Speed and Performance: Optimized for fast performance, reducing loading times and improving user experience.
- Full-Stack Integration: Seamlessly integrates with Laravel’s existing features and packages, allowing for a unified development experience.
- Hotwire Compatibility: Utilizes Hotwire to provide real-time updates without needing full page reloads, enabling smooth user interactions.
- Minimal JavaScript: Reduces the need for complex JavaScript frameworks, allowing developers to write more backend code while still delivering interactive features.
- Automatic Data Handling: Handles data submission and updates automatically, simplifying the process of building dynamic interfaces.
Installation
You can install Laravel Turbo via Composer. First, make sure you have a Laravel application set up. Then, run the following command:
bash
1 |
composer require laravel/turbo |
Configuration
After installing the package, you may need to publish the configuration file:
bash
1 |
php artisan vendor:publish --provider="Laravel\Turbo\TurboServiceProvider" |
This will create a configuration file in your config
directory where you can adjust various settings.
Basic Usage
Setting Up a Controller
You can create a controller to handle requests and return responses. For example, you can create a PostController
that handles creating and displaying posts.
php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
namespace App\Http\Controllers; use App\Models\Post; use Illuminate\Http\Request; class PostController extends Controller { public function index() { $posts = Post::all(); return view('posts.index', compact('posts')); } public function store(Request $request) { $post = Post::create($request->all()); return response()->turboStream()->append('posts', view('posts.partials.post', compact('post'))); } } |
Creating Views
You can create Blade views that utilize Turbo to render dynamic content. For instance, in resources/views/posts/index.blade.php
blade
1 2 3 4 5 6 7 8 9 10 11 |
<div id="posts"> @foreach ($posts as $post) @include('posts.partials.post', ['post' => $post]) @endforeach </div> <form method="POST" action="{{ route('posts.store') }}" data-turbo-action="replace" data-turbo-frame="posts"> @csrf <input type="text" name="title" required> <button type="submit">Create Post</button> </form> |
And in resources/views/posts/partials/post.blade.php
, define how each post looks:
blade
1 2 3 |
<div class="post"> <h2>{{ $post->title }}</h2> </div> |
Turbo Frames
Turbo frames allow you to replace specific parts of your page with content from the server without reloading the entire page. You can wrap parts of your views in <turbo-frame>
elements:
blade
1 2 3 4 5 |
<turbo-frame id="posts"> @foreach ($posts as $post) @include('posts.partials.post', ['post' => $post]) @endforeach </turbo-frame> |
Real-Time Updates
With Laravel Turbo, you can easily handle real-time updates. You can use events to broadcast changes to your application, ensuring that users always see the latest data without refreshing the page.
Conclusion
Laravel Turbo simplifies the development of full-stack web applications by combining server-side logic with client-side interactivity. Its integration with Laravel’s ecosystem allows developers to build modern applications quickly and efficiently, minimizing the need for complex frontend frameworks while still delivering responsive user experiences.
- Laravel Breeze – Simple authentication starter kit
- Laravel Jetstream – Scaffolding for Laravel apps
- Laravel Passport – API authentication via OAuth2
- Laravel Sanctum – Simple API authentication
- Spatie Laravel Permission – Role and permission management
- Laravel Cashier – Subscription billing with Stripe
- Laravel Scout – Full-text search using Algolia
- Laravel Socialite – OAuth authentication (Google, Facebook, etc.)
- Laravel Excel – Excel import and export for Laravel
- Laravel Horizon – Redis queues monitoring
- Laravel Nova – Admin panel for Laravel
- Laravel Fortify – Backend authentication for Laravel
- Laravel Vapor – Serverless deployment on AWS
- Laravel Telescope – Debugging assistant for Laravel
- Laravel Dusk – Browser testing
- Laravel Mix – API for compiling assets
- Spatie Laravel Backup – Backup management
- Laravel Livewire – Building dynamic UIs
- Spatie Laravel Media Library – Manage media uploads
- Laravel Excel – Excel spreadsheet handling
- Laravel Debugbar – Debug tool for Laravel
- Laravel WebSockets – Real-time communication
- Spatie Laravel Sitemap – Generate sitemaps
- Laravel Spark – SaaS scaffolding
- Laravel Envoy – Task runner for deployment
- Spatie Laravel Translatable – Multilingual model support
- Laravel Backpack – Admin panel
- Laravel AdminLTE – Admin interface template
- Laravel Collective Forms & HTML – Simplified form and HTML generation
- Spatie Laravel Analytics – Google Analytics integration
- Laravel Eloquent Sluggable – Automatically create slugs
- Laravel Charts – Chart integration
- Laravel Auditing – Track changes in models
- Laravel JWT Auth – JSON Web Token authentication
- Laravel Queue Monitor – Monitor job queues
- Spatie Laravel Query Builder – Filter, sort, and include relationships in Eloquent queries
- Laravel Datatables – jQuery Datatables API
- Laravel Localization – Multilingual support for views and routes
- Laravel Acl Manager – Access control list manager
- Laravel Activity Log – Record activity in your app
- Laravel Roles – Role-based access control
- Spatie Laravel Tags – Tagging models
- Laravel Installer – CLI installer for Laravel
- Laravel Breadcrumbs – Generate breadcrumbs in Laravel
- Laravel Mailgun – Mailgun integration for Laravel
- Laravel Trustup Model History – Store model change history
- Laravel Deployer – Deployment automation tool Advertisement
- Laravel Auth – Custom authentication guards
- Laravel CORS – Cross-Origin Resource Sharing (CORS) support
- Laravel Notifications – Send notifications through multiple channels
- Spatie Laravel Http Logger – Log HTTP requests
- Laravel Permission Manager – Manage permissions easily
- Laravel Stubs – Customize default stubs in Laravel
- Laravel Fast Excel – Speed up Excel exports
- Laravel Image – Image processing
- Spatie Laravel Backup Server – Centralize backups for Laravel apps
- Laravel Forge API – Manage servers through the Forge API
- Laravel Blade SVG – Use SVGs in Blade templates
- Laravel Ban – Ban/unban users from your application
- Laravel API Response – Standardize API responses
- Laravel SEO – Manage SEO meta tags
- Laravel Settings – Store and retrieve settings
- Laravel DOMPDF – Generate PDFs
- Laravel Turbo – Full-stack framework for building modern web apps
- Spatie Laravel Event Sourcing – Event sourcing implementation
- Laravel Jetstream Inertia – Jetstream’s Inertia.js integration
- Laravel Envoy Tasks – Task automation
- Laravel Likeable – Like/dislike functionality
- Laravel GeoIP – Determine visitor’s geographic location
- Laravel Country State City – Dropdowns for country, state, and city
- Laravel Hashids – Generate short unique hashes
- Laravel Repository – Repository pattern for Laravel
- Laravel UUID – UUID generation for models
- Spatie Laravel Medialibrary Pro – Enhanced media management
- Laravel Queue Monitor – Monitor Laravel job queues
- Laravel User Activity – Monitor user activity
- Laravel DB Snapshots – Create database snapshots
- Laravel Twilio – Twilio integration
- Laravel Roles – Role-based permission handling
- Laravel Translatable – Add translations to Eloquent models
- Laravel Teamwork – Manage teams in multi-tenant apps
- Laravel Full Text Search – Add full-text search to Laravel models
- Laravel File Manager – File and media management
- Laravel User Timezones – Automatically detect user time zones
- Laravel ChartsJS – Render charts with ChartsJS
- Laravel Stripe – Stripe API integration
- Laravel PDF Generator – PDF generation
- Laravel Elasticsearch – Elasticsearch integration
- Laravel Simple Qrcode – Generate QR codes
- Laravel Timezone – Manage timezones and conversions
- Laravel Collective API – API management for Laravel
- Laravel Rest API Boilerplate – REST API starter kit
- Laravel Multi Auth – Multi-authentication functionality
- Laravel Voyager – Admin panel for Laravel
- Laravel Voyager Database – Database manager for Voyager
- Laravel Categories – Handle categories for models
- Laravel Multitenancy – Multi-tenancy implementation
- Laravel Access Control – Advanced access control for users
- Laravel Menus – Menu management
- Laravel Translatable Routes – Multilingual route handling