With Laravel 6 (released in September 2019) came an update to the versioning scheme of Laravel, it's now following semantic versioning. Because of this change, a major release is released every six months.
Laravel 7 is packed with new features we at OrangeTalent are pretty excited about.
Route performance improvements
Because of an improvement to the Symfony router component, routes will be matched twice as fast when using route caching (php artisan route:cache
).
<blockquote class=\"twitter-tweet\"><p lang=\"en\" dir=\"ltr\">Initial benchmarks of "Hello World" request / response cycle for an application with 800 routes in Laravel 7.x + route:cache are twice as fast as Laravel 6.x + route:cache thanks to using <a href=\"https://twitter.com/symfony?ref_src=twsrc%5Etfw\">@symfony's new more performant matcher. 🚀 Thanks to <a href=\"https://twitter.com/driesvints?ref_src=twsrc%5Etfw\">@driesvints for the work on this.
— Taylor Otwell 🏝 (@taylorotwell) <a href=\"https://twitter.com/taylorotwell/status/1228423654511390726?ref_src=twsrc%5Etfw\">February 14, 2020 <script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\">ZTTP
Guzzle is a great HTTP client for PHP, but it can sometimes be a bit verbose. As of this release Laravel provides a thin layer on top of Guzzle to make performing requests easier and cleaner.
$response = Http::withHeaders(['user-agent' => 'OrangeBot'])->post('blog', [
'title' => 'Laravel 7',
]);
We plan on migrating to the new HTTP client for our integrations with external services.
Anonymous Components
Our Belgian friends at Spatie launched Blade X a few years ago. It allows you to use Blade components in a Vue-like style.
// Without Blade X
@include('myAlert', ['type' => 'error', 'message' => $message])
// With Blade X
<my-alert type=\"error\" :message=\"$message\" />
This feature has now been implemented in Laravel:
// welcome.blade.php
<x-avatar size=\"100\" />
// components/avatar.blade.php
@props(['user', 'size'])
<img
class=\"d-inline-block rounded-circle\"
src=\"{{ $user->gravatarUrl($size) }}\"
width=\"{{ $size }}\"
height=\"{{ $size }}\"
/>
Custom Casts
This allows defining your own cast classes:
class Post extends Model
{
public $casts = [
'name' => StringCast::class,
];
}
class StringCast implements CastsAttributes
{
public function get($model, string $key, $value, array $attributes)
{
return str_split($value);
}
public function set($model, string $key, $value, array $attributes)
{
return implode('', $value);
}
}
Custom Stubs
When running php artisan stub:publish
, a stubs folder be placed in your project, allowing you to modify the default stubs files (used when you run make:model
/ make:controller
etc.).
Airlock
Building an authentication API for PWA & mobile apps has always been a kind of a pain. Airlock provides a nice built-in system for authentication using regular Laravel sessions. This also makes using authentication in external applications easier and more secure.
Route Model Binding Improvements
It's now possible to define a binding column per route, so the model is automatically bound in the controller:
Route::get('posts/{post:slug}', function (Post $post) {
return $post;
});
Conclusion
We can't wait to upgrade our projects to Laravel 7 in the coming months! And many more features are coming in the new Laravel 7 release. Follow the release notes to see what’s new.