Laravel 8’s new features

Sudeep Misra
3 min readMar 23, 2021

Laravel version 8 now, comes with some really cool features which definitely help to build a robust Laravel application.

New features include Laravel Jetstream, model factory classes, migration squashing, job batching, improved rate-limiting, queue improvements, dynamic Blade components, Tailwind pagination views, time testing helpers, improvements to artisan serve, event listener improvements, and a variety of other bug fixes and usability improvements. we will discuss some of them in this blog.

# Laravel Jetstream

Laravel Jetstream provides application scaffolding for Laravel also the perfect starting point for your next project and includes :

  • login
  • registration
  • email verification
  • two-factor authentication
  • session management
  • API support via Laravel Sanctum
  • optional team management

Laravel Jetstream replaces and improves upon the legacy authentication UI scaffolding available for previous versions of Laravel.

Jetstream is designed using Tailwind CSS and offers your choice of Livewire or Inertia scaffolding.

# Models Directory

Before the last update, there was not a separate directory for Models. but by overwhelming community demand, the default Laravel application skeleton now contains an app/Models directory — and I personally enjoy this home for my eloquent models.

# Model Factory Classes

Thanks to Taylor Otwell.

Eloquent model factories are now class-based starting in Laravel 8, with improved support for relationships between factories (i.e., a user has many posts). I think you will agree how awesome the new syntax is for generating records via the new and improved model factories:

use App\Models\User;
User::factory()->count(50)->create();
// using a model state "suspended" defined within the factory class
User::factory()->count(5)->suspended()->create();

# Migration Squashing

As you build your application, it may contain many migration files, you can now squash them into a single SQL file. This file will be executed first when you run migrations, followed by any remaining migration files that are not part of the squashed schema file. Squashing existing migrations can decrease migration file bloat and possibly improve performance while running tests.

php artisan schema:dump// Dump the current database schema and prune all existing migrations...
php artisan schema:dump --prune

When you execute this command, Laravel will write a “schema” file to your database/schema directory. Now, when you attempt to migrate your database and no other migrations have been executed, Laravel will execute the schema file's SQL first.

# Job Batching

Laravel’s job batching feature allows you to easily execute a batch of jobs and then perform some action when the batch of jobs has completed executing.

The new batch method of the Bus facade may be used to dispatch a batch of jobs.

Of course, batching is primarily useful when combined with completion callbacks. So, you may use the then, catch, and finally methods to define completion callbacks for the batch.

To learn more about job batching, visit the queue documentation.

# Dynamic Blade Components

Sometimes you need to render a blade component dynamically at runtime. Laravel 8 provides the <x-dynamic-component/> to render the component:

<x-dynamic-component :component="$componentName" class="mt-4" />

These are some new features that I found really cool and I’m gonna use them in my daily life Laravel things. I hope you came to know about some really cool kind of stuff after reading this blog.

Help me with building a developer’s community: CodewithSudeep

--

--