Best New Features in Laravel 8

Laravel 8, the most recent version of the Laravel framework, was released on September 8. Laravel creator Taylor Otwell announced some of those new features in his Laracon presentation. This post contains a summary of some of the new capabilities announced. Let’s take a look at some of those great new features!

1. app/Models Directory

1. app/Models Directory

The artisan:make model command will create the model in the app/Models directory. This feature was decided after Taylor asked people on Twitter how they feel about this.

To those in the “app/Models” camp. What do you do when you have 1 class that isn’t a model — it’s just a regular class? Since you have set a precedent that no files can live in “app” directory, do you create some “Misc” folder? “Libraries”? 😬

— Taylor Otwell 🛸 (@taylorotwell) June 30, 2020

Spicy Monday poll… don’t respond with some “I follow DDD and put them in contextual directories” thing either 💋

— Taylor Otwell 🛸 (@taylorotwell) June 29, 2020

If you don’t like that, it’s possible to delete the app/Models directory and artisan will create the model file in the app/ folder. It’s cool that Laravel is built with so much input from the community!

2. New Landing Page

Laravel 8 comes with a new landing page for a brand new install. It is now redesigned and It is built using TailwindCSS, includes light and dark-mode capabilities, and by default extends links to SaaS products and community sites.

3. Controllers Routing Namespacing

No more double prefix issues! In previous versions of Laravel, the RouteServiceProvider had an attribute called namespace that was used to prefix the controllers in the routes files. That created a problem when you were trying to use a callable syntax on your controllers, causing Laravel to mistakenly double prefix it for you. This attribute was removed and now you can import and use it without the issue.

It can also be used for single action controllers that have the __invoke method.

4. Route Caching

Laravel uses route caching to compile your routes in a PHP array that is more efficient to deal with. In Laravel 8, it’s possible to use this feature even if you have closures as actions to your routes. This should extend the usage of route caching for improved performance.

5. Attributes on Extended Blade Components

In Laravel 7 the child components didn’t have access to the $attributes passed to it. In Laravel 8 these components were enhanced and it is now possible to merge nested component attributes. This makes it easier to create extended components.

6. Better Syntax for Event Listening

In the previous versions of Laravel, when creating a closure-based event listener there was much repetition and a cumbersome syntax.

In Laravel 8 it’s simpler and cleaner:

7. Queueable Anonymous Event Listeners

In Laravel 8 it is possible to create queueable closure from anywhere in the code. This will create a queue of anonymous event listeners that will get executed in the background. This feature makes it easier to do this, while in previous versions of Laravel you would need to use an event class and an event listener (using the ShouldQueue trait).

8. Maintenance Mode

This is especially useful when you need to do some maintenance on your application and you want to take it down for your users but still let your developers investigate bugs. This will create a secret cookie that will be granted to whoever hits the correct endpoint, allowing it to use the application while in maintenance mode.

Pre-rendering an error view is a safe way for not exposing errors to your end user when your application is down (during a new deployment, for example). The Laravel 8 framework guarantees that your predefined error page will be displayed before everything else from the application.

This combines the new features and will make the application only display a single predefined route, while still allowing for the people who have the secret to test and debug. This can be very useful when launching a new app.

9. Closure Dispatch “Catch”

Laravel has a pretty robust queue system that accepts a closure queue that will get serialized and executed in the background. Now we have a way to handle failures in case your job fails.

10. Exponential Backoff Strategy

This is an algorithm that decreases the rate of your job in order to gradually find an acceptable rate.

Now Laravel has this capability too, which is handy for jobs that deal with external APIs, where you wouldn’t want to try again on the same amount of time. It can also be used to dynamically generate the return array, setting different times to wait before retrying.

11. Job Batching

Modeled after the Sidekiq and Ruby library, job batching makes it easy to handle many jobs at the same time concurrently. It’s also easy to be notified when all jobs are complete, or when there’s any error on it’s execution. You can see more details on the PR that added this functionality.

12. Rate Limiting

Rate limiting provides a new and more convenient way of limiting the use of your routes.

13. Schema Dumping

Schema dumping is a way to squash migrations to a single file. It generates a schema file that has the whole schema for your database in a SQL form. This is used during development, useful for integrating new developers on your project that already has a large number of migrations. It supports MySQL, Postgres, SQLite.

14. Model Factories

Model factories are class based factories that add a lot of new features to Laravel 8. For each model there’s also a factory class, where there is a definition method that says which attributes it will generate for that model. Your models make use of that factory through the Factory trait.

Factories are rewritten for Laravel 8 to be class based. 🦩 pic.twitter.com/2ODeIfktsC

— Laravel News (@laravelnews) August 26, 2020

15. Laravel Jetstream

Laravel Jetstream is a brand new scaffolding for Laravel released as an open-source package. It builds an application using TailwindCSS and TailwindUI, includes login, registration, two-factor authentication, session management. It offers two versions for handling frontend: Livewire (TALL Stack) or InertiaJS (VueJS)

If you have any Laravel-related questions or projects, feel free to reach me on my LinkedIn account & email address.

--

--

--

I’m a professional and passionate Full Stack Developer with ability to write Test-Driven and Clean code from scratch through Laravel and Vue.JS/ React.Js.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How To Make Apple Apps On Mac

Pyhist: A Python utility to automagically update the package version from the git history and…

mDevCamp 2019: our experience | Apiumhub

5 Highest Paying Tech Jobs for Freshers(For Engineers and Non — Engineers)

🗣Meme Contest Alert🔥🔥🔥‬

Teeslion customer care number 6299325726//6299325726 help refund ke liye call karein thank you so…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rizwan Azhar

Rizwan Azhar

I’m a professional and passionate Full Stack Developer with ability to write Test-Driven and Clean code from scratch through Laravel and Vue.JS/ React.Js.

More from Medium

What’s New In Laravel 9 (Part 1)

Build Simple REST API with Laravel

How To Use Enums With Laravel 9?

Laravel Real-Time Notifications with Pusher