What Is New in Laravel 5.6
Laravel 5.6 is a Long Term Support (LTS) release packed with developer-focused enhancements. It introduces a new logging system, job middleware, dynamic rate limiting, and significant frontend tooling improvements.
| Category | Key Changes |
|---|---|
| New Features | Logging system overhaul, Broadcast channel classes, Job Middleware, API controller generation, Blade component aliases |
| Improvements | Dynamic rate limiting, Frontend scaffolding, UUID methods, Eloquent date formatting |
| Developer Tools | php artisan preset command, Eloquent::find for collections |
How does the new logging system work?
Laravel 5.6 completely revamps logging to use the Monolog library by default. This provides a unified, channel-based system for handling log messages.
You can now configure multiple log "channels" in config/logging.php, each writing to different locations like single files, daily files, the system log, or even Slack. In practice, this makes it much easier to segregate logs for different parts of your application without extra packages.
What are Job Middleware and why use them?
Job Middleware allows you to wrap custom logic around the execution of queued jobs. This is perfect for tasks that need to run before or after every job in a centralized location.
You might use this to rate limit jobs, add logging, or handle transactions. Instead of cluttering your job's handle method with this boilerplate, you create a middleware class. This keeps your job logic clean and focused on its actual task.
class MyJobMiddleware
{
public function handle($job, $next)
{
// Logic before job runs
$next($job);
// Logic after job runs
}
}
How is rate limiting more dynamic now?
Previous rate limiting was static. In 5.6, you can define dynamic rate limits based on the current authenticated user or incoming request.
The throttle middleware now accepts a closure, letting you calculate max attempts and decay minutes on the fly. This matters because you can implement more granular limits, like giving premium users a higher request quota than free users.
Route::get('/api/user', function () {
//
})->middleware('throttle:10,1'); // Static (old way)
Route::get('/api/user', function () {
//
})->middleware('throttle:rate_limit'); // Dynamic (new way)
What improvements were made for frontend development?
The frontend scaffolding got a significant upgrade. The preset command was introduced, making it trivial to switch between popular frontend frameworks like React and Vue.
Running php artisan preset react instantly scaffolds a fresh Laravel installation with React components. This streamlines the setup process and reflects the framework's focus on modern full-stack development.
Are there any new Eloquent shortcuts?
Yes, two handy Eloquent methods were added. The find method now accepts a collection of primary keys, returning a collection of all found models.
Additionally, the uuid column type was introduced for migrations. This is a convenience method for generating UUID columns if your application uses them as primary keys instead of auto-incrementing integers.
$users = User::find([1, 2, 3]); // Returns Eloquent collection
// In a migration
$table->uuid('id')->primary();
$table->uuid('custom_column');
FAQ
Is Laravel 5.6 an LTS release?
Yes, Laravel 5.6 is a Long Term Support (LTS) release. This means it received bug fixes for 2 years and security fixes for 3 years from its release date.
How do I create a Broadcast channel class?
Use the new Artisan command: php artisan make:channel OrderChannel. This generates a channel class where you define authorization logic, moving it out of your routes/channels.php file for better organization.
Can I generate API-only controllers?
Absolutely. The make:controller command now has a --api flag. Running php artisan make:controller API/UserController --api generates a controller with methods for a typical API resource, excluding the create and edit methods used for HTML forms.
What are Blade component aliases?
This feature lets you alias components for easier referencing in your templates. Instead of using a full path like @component('admin.components.alert'), you can register an alias in your AppServiceProvider and simply use @alert in your Blade files.
Was there a change to date serialization?
Yes, Eloquent now uses Carbon's new toJSON method for date serialization. This method returns dates in ISO-8601 format (e.g., 2019-12-02T20:01:00.283041Z), ensuring compatibility with JavaScript date parsing and ISO standards.