Chandresh Patel March 1st, 2021

What’s New in Laravel 8?

Laravel 6 was launched in September 2019, Laravel 7 arrived in March 2020 and Laravel 8 is here already. It won’t be an aggravation to say that nothing grew and moved forward while the CORONA pandemic is here than our favorite framework i.e. Laravel.

In this article, we have tried covering all the updates and feature updates/additions in the latest Laravel release (Laravel 8). To stay updated with the technological advancements related to it, read ahead.

Laravel 8 Release Highlights

Taylor Otwell, the founder of Laravel, announced the new release of the Laravel framework on September 8th, 2020. 

While explaining the details regarding Laravel 8 in the Laracon event, his focus remained on the little ‘quality of usage’ related changes before he proceeded to discuss the latest features, improvements, and policy updates.

Laravel Jetstream, migration squashing, time testing helpers, Laravel fortify, job batching, tailwind pagination view, and model factor classes were introduced in this release. Apart from this, improvements were made in rate-limiting, queue, artisan serve, event listeners, maintenance mode, and route caching.

Laravel has cleaner code and improvement functions than Laravel 7.x because the team worked upon optimizing the existing framework too. Laravel codebase as well as a few libraries were updated for betterment too. Also, a new landing page is now there to welcome you now.

Detailed Updated [Laravel 8]

Here are the major improvements made in the Laravel 8 framework:

The latest Addition – Laravel’s Default App/Model Directory

Previously, the model class was present in the root app directory. However, with the release of Laravel 5, it was removed. As per the Laravel creator, around 80 percent of the Laravel developers were creating it manually. So, to simplify things for professionals, it is restored again.

With the release of the latest release, the app/models directory will be shipped with the Laravel 8 (or later) framework. So, if you will use any artisan generator command to create a model, it will be added in the app/models directory.

If you don’t want it and wish to create models in the app directory, you can remove the models directory.

Laravel Jetstream

Its launch is the biggest announcement made by Taylor while releasing the latest framework. 

Laravel Jetstream is the replacement for the Laravel/ui package that used to enable basic authentication scaffolding. This package was to provide you with the code of a fully-function frontend and backend code of the login module of your application.

Now Laravel Jetstream is much advanced than its legacy. It is well-designed Laravel application scaffolding, created using Tailwind CSS. This time, Jetstream isn’t limited to login and registration functionality anymore. 

The major built-in abilities of the Jetstream for Laravel application development include:

  1. Login and registration 
  2. Two-factor authentication through Google Authenticator or similar apps
  3. Email verification 
  4. Team management capacity 
  5. The option to delete accounts, edit profile, and change password
  6. Browser session management functionality 
  7. API support enabled through Laravel Sanctum 
  8. Improved authentication UI scaffolding 

With Laravel Jetstream, developers may make a choice between Livewire scaffolding and Inertia scaffolding now. 

As it is powered by JavaScript, the whole interface works without page reloads, improving the feel of the Laravel applications big time.

Laravel Fortify

Laravel Fortify is shipped with Laravel 8 and you can run the route:list’ artisan command to figure out the routes registered route by it.

It is a frontend agnostic authentication capability that synchronizes with Laravel to enable your related implementations. All kinds of validations and authentications related to login, password reset, registration, adding/editing email ID and more happens through it. 

You may use Fortify in combination with Laravel Jetstream or without it. If you are using it separately, it is advised to enable its registration, reset the password, and email verification feature only.

New Model Factories feature and Related Updates

In the Laravel 8 framework, you will find that the model factories feature is written from scratch. It is now more powerful, easy-to-use, and has a class-based code.

What it means is that Laravel factories are now object-oriented and extend the ‘Factory’ class. 

While the UserFactory used to return specific model attributes and was defined with a Closure, it is a separate class in Laravel 8. For each of your models, your factor class ‘UserFactory’ has a definition() method. This method/function returns the array of attributes, just as the UserFactory function in Laravel 7.

There is a HasFactory trait that gives you a function named factory() for your model classes. Using the instance returned by factory method(), one can call create(), make(), and other methods.

You may study this new implementation fully, in order to understand how to use it for fluently creating a better interface. 

Migration Squashing 

For large applications requiring multiple database migrations, Laravel 8 has a new feature to simplify the process. It is called Migration Squashing & allows schema dumping. It is well-aligned to remain compatible with most-used Database drivers such as SQLite, PostgreSQL, and MySQL for now. There are chances that the support for this feature will be extended to MSSQL and other DB Engines.

Now when you will need to open your migration folder, you won’t have to do the scrolling for minutes. Instead, you can condense your migration files to a single SQL file using the php artisan schema:dump command. It will write your schema in the ‘database/schema’ directory as raw SQL.

Add ‘–prune’ to this command when you want to delete your existing migration files.

Job Batching and more

It’s another amazing feature added to Laravel 8!

Job batching lets you add multiple jobs to a batch, queuing them for simultaneous execution. The completion of each job can be registered with callbacks (when(), catch() or finally()) to fire. You can access the status of the jobs on batches, cancel batches and handle errors using the $batch object.

You may use the backoff() function with your job classes to return the wait time to attempt the next job when a job fails.

It is now also doable to send closure to the background processes for error handling in queued batches.

Improvements in Rate Limiting

Beginning from Laravel 8, developers can define multiple rate limiters, assign them names, give them closure and return relevant details. It all is possible through RateLimiter Facade. Its capability is 50 login requests a minute.

You will have to use the RateLimiter facade with the ‘for’ function in app/Providers/RouteServiceProvider.php to utilize this new functionality.

The rate-limiting capability of Laravel 8 can be used with ‘throttle’ middleware API just as before. The only difference is that you can now pass names instead of integers.

Elimination of Controllers Namespace Prefix

The $namespace property in the previous was an automatic prefixed to the namespaces of your controllers. In this scenario, using the callable syntax in the web.php routes file used to add another prefix, causing an issue of double prefixes. With the launch of Laravel 8, the $namespace property is now set to ‘null’ for the Route Service Provider.

Bypass Token Creation & Pre-render Page for Maintenance Mode

Now, you need not explicitly specify the IPs that should be allowed to view the application when it is disabled for maintenance purposes. Instead of this, you can use the ‘secret’ option and set a Passcode. Savior, isn’t it?

Also, you can use the ‘render’ option to add a pre-rendered view or showing the error type to your visitors while the site in the maintenance duration.

The Final Word

Laravel 8 is a big release that has improved many things and added a lot of things to the Laravel framework. Apart from the above-listed updates, route caching functionality is now improved even more and the syntax for closure-based event listeners is optimized too. You can now use blade component attributes, starting from Laravel 8. Though we have covered almost everything related to the Laravel 8 release, you may refer to release notes too.


Photo by Charles Deluvio on Unsplash

Chandresh Patel

Chandresh Patel is a CEO, Agile coach and founder of Bacancy Technology. His truly entrepreneurial spirit, skillful expertise and extensive knowledge in the Agile software development services have helped the organization to achieve new heights of success. Chandresh is fronting the organization into global markets in a systematic, innovative and collaborative way to fulfill custom software development needs and provide optimum quality services.

Leave a Reply

Your email address will not be published. Required fields are marked *