Laravel 8 has been released and includes many new features such as Laravel Jetstream, a unique directory for models, model factory classes, migration squashing, improvements to quota limitations (rate-limit), helpers for testing dates and time, dynamic blade components, and many other features.
Before we continue the article with the new features of version 8, remember that starting from version 6, Laravel follows SemVer (Semantic Version) and releases a new major version every six months.
Read the article Laravel Framework – What is it to better understand the framework
Laravel Jetstream
Laravel Jetstream is a scafolding application designed with a modern interface for Laravel.
Jetstream provides the perfect starting point for your next Laravel application and includes login, user registration, email verification, two-factor authentication, session management, API support via Laravel Sanctum and optional team management.
Jetstream is designed using Tailwind CSS and offers your choice of skeletons for Livewire or Inertia.
Template Directory
The Laravel 8 application skeleton now includes a model-specific directory under app/Models
.
All generator commands - php artisan make
, assume models exist in app/Models
; however, if this directory does not exist,
the framework assumes that the application maintains the models within the root app/
folder.
Model factory classes
Eloquent model factories are now based on classes as of Laravel 8, with improved support for relationships between factories, eg one user has many posts.
Migration Squashing
If your application contains many migration files, you can now compress them into a single SQL file.
This file will run first when running migrations, followed by any remaining migration files that are not part of the compressed schema file.
Dropping existing migrations minimizes migration file “bloat” and possibly improves performance when running tests.
Improved Rate limiting
Laravel 8 brings improvements to the existing quota throttling functionality, while providing backward compatibility with existing throttle middleware and offering more flexibility.
Laravel 8 has the concept of Rate Limiters that you can set via a facade.
Test helpers for time
Developers already have, with Laravel, full control over time modification through the excellent library Carbon PHP.
In version 8 of Laravel a new step was added, providing helpers that help with handling time within tests. Briefly explaining, when using these methods, for example, the time can be reset (zeroed) between each test.
Dynamic Components in Blade
It’s common that you need to render a Blade component dynamically at runtime. Now Laravel 8 to render the component provides the:
<dynamic-component>
Removing default route namespace from controllers
As of version 8 of Laravel, the “namespacing” of the default route for the Controllers is not defined, this way, in order for you to associate a route to a controller action, you must import the controller in the routes file, as explained in official documentation:
use App\Http\Controllers\UserController;
Route::get('/user', [UserController::class, 'index']);
However, this “new way” of declaring the routes has generated some confusion, and causing the error “Target class does not exist”.
While this change is backwards compatible, meaning older projects that used Laravel 7.x can easily migrate to Laravel 8.x without changing anything, new projects created in Laravel 8 should take this into account.
The problem arising from this change in your newly created Laravel 8 applications, when trying to load the routes you encounter an exception like:
Target class [MeuController] does not exist.
As already mentioned, the problem is not necessarily related to a code error, but to a necessary adjustment, especially considering that 99.9% of the tutorials about Laravel (at least up to version 7) do this.
If you are experiencing this “problem”, read the article How to fix the “Target class does not exist” error in Laravel 8.
To learn more about Laravel 8
These are just some of the new features in Laravel 8, for a complete list read the project release notes as well as the upgrade guide. To get an overview of the Laravel Framework read the article Laravel Framework – What is it.
Comments