Top 11 Features Of Laravel 8 That You Must Know

  Solace  Infotech    April 16, 2021    418

 

Laravel is the most popular framework for development with a huge community support. After the release of laravel 8, this PHP framework will continue to bring new and improved features with every version. If you are thinking of using laravel for your next project, then you must know the improved features of laravel 8. So, here we’ll see the new features of laravel 8. But before getting into the details, let us discuss why you should choose Laravel over other frameworks. 

Reasons To Choose Laravel For Development Over Other Frameworks-

1. Security-

Security is a critical factor which needs more attention than other aspects of web apps. Around there, a Laravel development agency uses Laravel and delivers a seamless and impenetrable level of security.

You can know the reasons of – why enterprises should opt for laravel development services

2. Environment-

Laravel provides an interactive environment for project development. Hence programmers can easily handle their tasks. Also it streamlines the complex and longer tasks, and simplifies them reasonably.

3. Tools Of Learning-

Laravel is best suited framework for web projects because it can offer advanced learning sources, practice sessions and Laracasts. This framework provides tutorials and free tutorials through which developers can solve most challenging problems through coding.

Features Of Laravel 8-

1. New Landing Page-

Laravel 8 brings with it a new landing for new installation. Laravel creators redesigned and built it from scratch using TailwindCSS. Accordingly, designers can choose between light and dark modes. Also, by default, it can extend links to community sites and SaaS products.

2. Laravel Jetstream-

A new Laravel application scaffolding, Laravel Jetstream, was released with Laravel 8. Jetstream provides a great starting point for laravel app with built-in options as follows-

  • Two-factor authentication (2FA)
  • Email verification
  • Laravel Sanctum API support
  • Designed with Tailwind CSS
  • Session management
  • Login and registration
  • Choice of two frontend stacks: Livewire + Blade or Inertia.js + Vue.js

How to use Laravel Jetstream?

One can create a new app with Jetstream by using Laravel installer. Just insure that the Laravel installer is updated to v4.0, and then run following-

laravel new your-project --jet

You can choose Inertia or Livewire. Next, run your database migrations with:

php artisan migrate

You can see your application at http://localhost:8000 by running

php artisan serve

If you’d prefer to use Composer, you can get the Composer installation instructions in the Laravel Jetstream documentation.

3. Models Directory (Default app/models directory)-

Laravel 8 provides a default app/models directory instead of leaving the model class in the root app directory as in the previous laravel versions.

You can create model using artisan command-

php artisan make:model modelName

When you want to keep your models in your app directory, delete the models directory, generator commands will respect that and create the model classes in app directory.

4. Model Factory Classes-

Model factories are now class-based starting in Laravel 8, with improved support for relationships between factories (i.e., a user has numerous posts). Now, you know the awesome new syntax is for generating records via 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();

 

5. Migration Squashing-

Laravel version 8 came with another great feature: migration squashing. Now you don’t need to scroll for five minutes when you open up your migrations folder. With migration squashing, you would now be able to gather your migration files into single SQL file with the commands-

php artisan schema:dump
php artisan schema:dump --prune

Laravel will write a new schema file to database/schema. When you run your migrations, Laravel will run the SQL from schema file first before moving on to anything created later in the migrations folder.

6. Rate Limiting Improvements-

Laravel 8 comes with improvements to existing rate limiting functionality while supporting backward compatibility with existing throttle middleware and providing more flexibility. Laravel 8 has Rate limiters that you can define through facade:

use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for('global', function (Request $request) {
    return Limit::perMinute(1000);
});

The for() method takes the HTTP request instance, that gives you complete control over limiting requests dynamically.

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 which will execute in the background. This feature eases to do this, while in previous versions of laravel you would need to use an event class and event listener (using ShouldQueue trait).

<?php
namespace App\Models;
use function Illuminate\Events\queueable;
class User extends Authenticable
{
   protected static function booting()
  {
    static::created(queueable(function (User $user) {
       info(‘Queued: ‘ . $user->name);
});
}
} 

8. Controllers Routing Namespacing-

In older Laravel versions, the RouteServiceProvider had an attribute called namespace that was used to prefix controllers in the routes files. That made an issue when you were trying to use a callable syntax on your controllers, making Laravel to mistakenly double prefix it for you. This attribute was eliminated 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.

Route::get( ‘/welcome’, [WelcomeController::class], ‘index’]);
Route::get( ‘/welcome’, WelcomeController::class);

 

9. Route Caching-

Laravel framework uses route caching to compile your routes in a PHP array that is efficient to manage. In laravel 8, you can use this feature, if you have closures as actions to your routes. This should extend the use of route caching for improved performance.

Route::get(‘/components’, function () {
   return view(‘button’);
});

10. Maintenance Mode: pre-rendered page –

In the older version, laravel 7, if you run php artisan down to put your site into maintenance mode while deploying app and then run Composer as a part of deployment, your app may still throw errors while your dependencies are changed and autoload file is written- means end user will see an error page, instead of maintenance mode page. This problem is solved in Laravel 8. Now you can pass name of a view to “render” as part of the artisan down command

For instance,

php artisan down --render="errors::back-soon"

Then, if anyone try to access the site, they will see the pre-rendered view, which means the errors won’t be thrown. 

Secret  Maintenance Mode-

php artisan down —secret=laracon-2020

Now you can access the route as a secret. You can use app routes during maintenance mode by using the above command.  There will be some options available in the artisan down command such as: render, redirect, status, and the secret to ensure much more control.

11. Exponential Backoff Strategy-

This algorithm decreases the rate of job so as to easily find an acceptable rate.

public function backoff()
{
 return [1, 5, 10];
}

Now laravel also has this capability, which is handy for jobs that manages external APIs, where you wouldn’t want to try again. Also, it can be used to dynamically create a return array, setting different times to wait before retrying.

Also know the laravel optimization tips for effective development at- Laravel optimization tips that you can’t miss in 2020


 Article keywords:
Laravel, technology, laravel 8

 


 Share this article: 
Print Digg StumbleUpon del.icio.us Facebook Yahoo! Buzz Twitter Google Bookmarks LinkedIn MySpace Orkut PDF Scoopeo Viadeo Add to favorites
      

© Copyright - Articles XP