Powerful New Web Development Features in Laravel 8
Powerful New Web Development Features in Laravel 8
Laravel is the most popular PHP framework, with more than 1.2 million websites built on it. Since its release in June 2011, Laravel has attracted the attention of many web developers, presenting itself as the most used PHP framework.
Laravel offers a rapid development environment, security and good developer guides. Created and maintained by its creator Taylor Otwell, Laravel has continued to make improvements to its software. It follows a semantic versioning scheme and is currently at version 8.x.
Here are eight new features to look out for in Laravel 8.
1. Laravel Jetstream
This is the new application scaffolding feature in Laravel. It comes with out of the box features like session tracking, login, registration, email verification, two-factor authentication and optional team management.
Jetstream offers the choice of two scaffolding options: Livewire and Inertia.
2. Migration Squashing
As you develop your application, your migrations might build up. You can “squash” them into a single SQL file to avoid the clatter. This option is available for MySQL or PostgreSQL users.
Laravel will create a schema file when the command schema:dump is executed. When you try to migrate your database, Laravel will first migrate the SQL file associated with your schema. Thereafter, if there are any migrations that weren't a part of the schema, they'll then be executed.
3. Tailwind CSS
Laravel now uses the Tailwind CSS framework as it’s default paginator. Tailwind is a CSS utility-first library which provides single-use CSS classes. It provides the advantage of having your styling information in one place rather than having it scattered. You can apply predefined classes directly to your HTML doc.
Tailwind also offers the ability to build responsive designs. It offers a mobile first system similar to that of Bootstrap. This implies that unprefixed utilities respond on all screen sizes while prefixed utilities come into effect at particular points.
Tailwind also features a just-in time mode enabled to have your styles generated on-demand rather than having everything rendered at initial build time. This makes it faster than using ordinary CSS. Another advantage this offers is that you don't need to get rid of your unused production styles, giving you the ability to use your code in multiple environments.
4. Job Batching
You can use this feature to run a batch of jobs at a given time and perform a certain action(s) when their execution is completed. The Bus facade provides a batch method which allows you to dispatch jobs.
5. Model Factory Classes
First, let's discuss model factories. These are used to seed your databases with test data. This fake data is important for testing purposes before any real user data is inserted.
In Laravel 8, the former Eloquent model classes have been completely replaced with class-based factories. With this, you can now manage object states by simply using methods. These methods typically call the state() method, which is given in the Laravel base factory class. The state() method takes in as an argument a function which will take in an array of attributes assigned to the factory.
6. Improved Maintenance
Previously, Laravel featured an allow list of IP addresses that you could use to access the application in maintenance mode. This has been removed and replaced with a simpler “secret” solution. You can specify the bypass token using the secret option.
While in maintenance mode, you can access your application URL and Laravel will automatically pass on the bypass cookie to your browser. Once the cookie is issued, you will access the application normally like it wasn’t in maintenance mode.
Your users may face errors if you use the PHP artisan down during deployment. To avoid this, Laravel offers the option to render a maintenance mode view that will be returned whenever a request is made. You can pre-render a template using the render option on the down command.
7. Time Testing Helpers
Laravel now includes the capability to enable you to manipulate the current time. You have the option to utilize your time attributes as milliseconds, hours, days, and so on.
Exciting Times Ahead for Laravel
Laravel is easy to learn and provides an elaborate developer guide with easy-to-follow examples. It provides bug fixes and patches on an almost weekly basis and major releases annually( around September). If you need more help, Laravel provides the Laracasts platform where you can get expert help. The platform provides paid web development lessons, though.
8. Improved Rate Limiting
Rate limiting allows you to manage the amount of traffic you receive on a certain route or group of routes. This can be achieved using the throttle middleware. The throttle middleware takes in the name of the rate limiter you want to use on a route. An HTTP request code (429) is returned if the incoming request exceeds a given rate limit.
In Laravel 8, the rate limiter has been built with more flexibility while still having backward compatibility. The rate limiter callback function allows you to dynamically build suitable rate limits established on authenticated users or incoming requests.