Updated Laravel 8 – New Features and Changes

Laravel 8

The latest version Laravel Jetstream, new Laravel application scaffolding has been released. If you are a user of Laravel or a newbie trying to know the features of Laravel, well, this is the right platform for you. You can always hire a Laravel developer to help you with Laravel 8.

Laravel Jetstream:

It gives great starting features to Laravel Applications having numerous in-built features like:

  • Registration and Login
  • Verification of Email with Two-factor Verification
  • Laravel Sanctum API support
  • Complete Management of Session
  • Two choices for your frontend- Livewire + Blade / Inertia.js + Vue.js
  • Already structures with Tailwind CSS

Method for using Laravel Jetstream:

Using Laravel installer you can get your new application with Jetstream. Keep in mind that the Laravel installer should have the latest updates to v4.0. Following this command, the following:

Laravel new your-project - -jet

From the two stacks (Livewire / Inertia) you must decide first which one you want to move further. Then run your database migration using;

Php artisan migrate 

You can view your application at http: //localhost: 8000 by functioning;

Php artisan serve

Once done, you are all set to go through your Laravel Jetstream application. It’s up to you if want to use Composer, details of installation are available in the Laravel Jetstream documentation.

Latest Updates in the Model:

The missing directory “App/Models” is back in action which was missing years ago in the Laravel 5 launch. Developers found that this directory was long gone with the Laravel 5 launch and new models can be made through the app directory. Well, it was running well but many developers found some unnecessary.

But the new Laravel 8 restored the app/Models directory. Again, it is up to you to use this directory or else you can opt for the previous directory by modifying your codebase to remove the Models directory.

Model factory Classes:

We can get a more clear idea about this after comparing the changes by viewing the default User factories from Laravel 7 and Laravel 8.

Factories in Laravel 8 are referred to as the classes that proceed further the base Laravel Factory class. When you will see the default file, you can find the model property and definition method. Returning the model attributes is done through the definition method.

When you do the comparison of this to Laravel 7 and others, you will find that “UserFactory” is explained as a Closure and returns characteristics of the specific model. Both the versions have access to Faker.

You will get clearer once, you will find out the differences while using the factories of Laravel 8 and Laravel 7.

Using factories in Laravel 7 vs Laravel 8

Before the launch of Laravel 8, you must be using the factory helper key in your seeder files for generating model instances but with Laravel 8, you get the privilege of using the factory straight on the model instance. It is due to the “HasFactory” trait which is now available in the default model of Laravel 8.

// database/seeders/UserSeeder.php
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// Create three App\User instances
User::factory(3)->create();
}
}
// app/Models/User.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
// ...
class User extends Authenticatable
{
use HasFactory;
// ...
}

Migration Squashing:

This is yet another addition to the new features of Laravel 8. No need to roll down and down for minutes while opening the migration folder.

Php artisan schema: dump
Php artisan schema:dump - - prune

New schema file to database/schema will be written by Laravel. Then Laravel will first be running the SQL from the schema file before going on to the later stuff in the migration folder. When you execute your migrations.

Job Batching:

Job Batching refers to accomplish something at the backend as it works as a part of the queue. The latest job batching gives you wings to perform several jobs at the same time.

Better Rate Limiting in Laravel 8

Rate limiting is upgraded in Laravel 8 and you can define rate limiters in Laravel 8 in app/Providers/RouteServiceProvider.php using the “for” method of the “RateLimiter”. The method “for” will recognise a name and a Closure, which helps in returning the rate-limiting details set up by you.

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

Once done, you may apply this rate limiter (which is pre-configured) with “throttle” followed by the name of the rate limiter.


Route::middleware(['throttle:login'])->group(function () {
Route::post('/login', function () {
//
});
Route::post('/register', function () {
//
});
});

Laravel 8 Maintenance Mode:

How can be mode be left unchanged when so many new features are enhancing the latest Laravel 8. This mode helps to “disable” your application at the time of amending some updates. In other versions, you just need to specify the IPs which will be allowed to use the application with the “allow” command:

Php artisan down - -allow=127.0.0.1 - -allow=192.168.0.0/16

But with the latest Laravel 8, no need to allow IPs explicitly. In place of that you can use the “secret” option for creating a maintenance mode bypass token;

Php artisan down - -secret= “1630542a-246b-4b66-afal-dd72a4c43515"

After that, you may access your app when it’s in maintenance mode simply attaching the token to the URL of your app.

Routing Namespacing

The namespace property in app/Providers/RouteServiceProvider.php in Laravel 8 is now set to null by default. While in the older versions, the “$namespace” properties are set to App\Http\Controllers.

The meaning of the change is that the controller route definitions will no longer be including automatic prefixing of the namespace.

Therefore, as you can see that there are a lot of new changes that have been made to enhance the functioning of the new Laravel 8. So, it is completely your decision to upgrade your older version and use the latest modified Laravel 8. If you are new to Laravel 8, you should hire Laravel developers in India, who guide you at each step to make your queries clearer. They have years of experience doing the same and thus will be the perfect choice for you to get help from them.

Share This Article