Framework versioning affects upgrade planning. Laravel 6 switches to semantic versioning, enabling predictable release schedules. Job middleware and improved authentication scaffolding enhance developer experience.
Semantic Versioning
New versioning scheme:
- Major releases: Breaking changes (e.g., 6.x to 7.x)
- Minor releases: New features, backwards compatible (e.g., 6.0 to 6.1)
- Patch releases: Bug fixes only (e.g., 6.0.1 to 6.0.2)
Release schedule:
- Major release: Every 6 months
- Minor releases: As needed
- Patch releases: Weekly (as needed)
- LTS releases: Every 2 years (Laravel 6 is LTS)
Job Middleware
Control job execution with middleware:
// app/Jobs/Middleware/RateLimited.php
namespace App\Jobs\Middleware;
use Illuminate\Support\Facades\Redis;
class RateLimited
{
public function handle($job, $next)
{
Redis::throttle('key')
->block(0)
->allow(10)
->every(60)
->then(function () use ($job, $next) {
$next($job);
}, function () use ($job) {
$job->release(60);
});
}
}
Apply middleware to jobs:
// app/Jobs/ProcessPodcast.php
use App\Jobs\Middleware\RateLimited;
class ProcessPodcast implements ShouldQueue
{
public function middleware()
{
return [new RateLimited];
}
public function handle()
{
// Job logic
}
}
Conditional middleware:
public function middleware()
{
return $this->user->isPremium()
? []
: [new RateLimited];
}
Laravel UI Package
Authentication scaffolding extracted:
# Laravel 6 requires separate package
composer require laravel/ui
# Generate auth scaffolding
php artisan ui bootstrap --auth
php artisan ui vue --auth
php artisan ui react --auth
Why separated?
- Cleaner core framework
- Flexibility in frontend choice
- Foundation for Laravel Jetstream (later)
Lazy Collection Improvements
Enhanced lazy operations:
use Illuminate\Support\LazyCollection;
// Remember values for multiple iterations
$collection = LazyCollection::make(function () {
for ($i = 1; $i <= 10; $i++) {
yield $i;
}
})->remember();
// First iteration calculates
$collection->each(function ($item) {
echo $item;
});
// Second iteration uses remembered values
$collection->each(function ($item) {
echo $item;
});
Takeuntil and takewhile:
$collection = LazyCollection::times(INF)
->takeUntilTimeout(now()->addMinute());
$collection = LazyCollection::make(function () {
while (true) {
yield random_int(1, 100);
}
})->takeWhile(function ($number) {
return $number < 90;
});
Authorization Gates
Guest user support in gates:
Gate::define('view-post', function (?User $user, Post $post) {
// Null user = guest
if ($post->published) {
return true;
}
return $user && $user->id === $post->author_id;
});
Eloquent Subquery Enhancements
Order by subquery:
// Order users by their latest post date
User::orderBy(
Post::select('created_at')
->whereColumn('user_id', 'users.id')
->latest()
->limit(1)
)->get();
Select with subqueries:
// Add latest post title to user query
$users = User::addSelect([
'latest_post_title' => Post::select('title')
->whereColumn('user_id', 'users.id')
->latest()
->limit(1)
])->get();
foreach ($users as $user) {
echo $user->latest_post_title;
}
Multiple Cache Keys Delete
Delete multiple keys at once:
// Before: Multiple calls
Cache::forget('key1');
Cache::forget('key2');
Cache::forget('key3');
// After: Single call
Cache::deleteMultiple(['key1', 'key2', 'key3']);
Multiple Mail From Addresses
Different from addresses per mailable:
// config/mail.php
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
// Override in mailable
class OrderShipped extends Mailable
{
public function build()
{
return $this->from('contact@zirasoftware.com', 'ZIRA Software Orders')
->view('emails.orders.shipped');
}
}
Job Batching Preparation
Foundation for Laravel 8 job batching:
// Jobs can now be configured with batch ID
// This feature fully implemented in Laravel 8
String Helpers
New string manipulation methods:
use Illuminate\Support\Str;
// Before/after specific string
Str::before('hello-world', '-'); // "hello"
Str::after('hello-world', '-'); // "world"
// Between two strings
Str::between('[hello]', '[', ']'); // "hello"
// PadBoth
Str::padBoth('James', 10, '_'); // "__James___"
// Plural
Str::plural('car', 2); // "cars"
Ignition Error Page
Beautiful error pages:
- Cleaner stack traces
- Code context
- Solution suggestions
- Better debugging experience
Upgrade from Laravel 5.8
Key changes:
# Update composer.json
"laravel/framework": "^6.0"
# Update Composer
composer update
# Clear caches
php artisan config:clear
php artisan cache:clear
php artisan view:clear
# Run migrations if needed
php artisan migrate
Breaking changes:
- String and array helpers moved to separate package
- Authentication scaffolding requires laravel/ui
- Some deprecated methods removed
Production Deployment
Optimize for production:
composer install --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache
php artisan view:cache
LTS Support
Laravel 6 support timeline:
- Bug fixes: 2 years (until September 2021)
- Security fixes: 3 years (until September 2022)
Perfect for long-term projects requiring stability.
Conclusion
Laravel 6 brings predictable semantic versioning and valuable features like job middleware. LTS support makes it ideal for enterprise applications requiring stability.
Planning a Laravel upgrade? Contact ZIRA Software for migration assistance.