www.makeuseof.com 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.

Livewire is a responsive and dynamic library that offers the ability to avoid using a JavaScript framework such as Vue.js. It uses the default Blade templating language. Livewire also offers the flexibility to choose between leaving Blade or using Vue.js.

Inertia uses Vue.js as its templating language.

Read More: What is Vue.js?

It gives the full power of Vue.js without the need for client-side routing. If Vue is your preferred templating language, then the Inertia stack is a good choice.

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.

www.makeuseof.com 8 Powerful New Web Development Features in Laravel 8

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.

It is also interesting to note that Laravel Jetstream was built using Tailwind.

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.

You can perform this in tandem with other completion callbacks like catch, then and finally to add functionality to your jobs.

use App\Jobs\ProcessPodcast;use App\Podcast;use Illuminate\Bus\Batch;use Illuminate\Support\Facades\Bus;use Throwable;$batch = Bus::batch([ new ProcessPodcast(Podcast::find(1)), new ProcessPodcast(Podcast::find(2)), new ProcessPodcast(Podcast::find(3)), new ProcessPodcast(Podcast::find(4)), new ProcessPodcast(Podcast::find(5)),])->then(function (Batch $batch) { // All jobs completed successfully…})->catch(function (Batch $batch, Throwable $e) { // First batch job failure detected…})->finally(function (Batch $batch) { // The batch has finished executing…})->dispatch();return $batch->id;

To get started you need to create a migration table that will contain job metadata such as completion rates. Use the command php artisan queue:batches-table to do this. And then php artisan migrate to migrate them. You can now define your batchable jobs and then dispatch then when ready.

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.

public function testTimeCanBeManipulated(){ // Travel into the future… $this->travel(5)->milliseconds(); $this->travel(5)->seconds(); $this->travel(5)->minutes(); $this->travel(5)->hours(); $this->travel(5)->days(); $this->travel(5)->weeks(); $this->travel(5)->years(); // Travel into the past… $this->travel(-5)->hours(); // Travel to an explicit time… $this->travelTo(now()->subHours(6)); // Return back to the present time… $this->travelBack();}

These helper functions make your work neat and easy to follow through by giving descriptive names to the methods.

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.

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.

For a web developer, Laravel is a must-have skill. It is open source, free to use and with a community of over 40,000 users. It is a technology worth keeping track of.




5 Web Frameworks Worth Learning for Developers

Interested in learning advanced web development? Avoid writing repetitive code—use these web development frameworks instead.

Read Next

Related Topics


Web Development

PHP Programming

About The Author

Jerome Davidson

(22 Articles Published)

Jerome is a Staff Writer at MakeUseOf. He covers articles on Programming and Linux. He’s also a crypto enthusiast and is always keeps tabs on the crypto industry.

More From Jerome Davidson

Subscribe to our newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!

Click here to subscribe

Leave a Reply

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