Laravel Framework


What’s new in Laravel 6.0

Category : Laravel Coding, Programming

Tags : Laravel, Laravel Development, Laravel Tutorial

Laravel is a web application framework with expressive, elegant syntax. Providing powerful tools needed for large, robust applications. The first version was released in June of 2011. However, the founder, Taylor Otwell, and his crew are actively improving it.

The latest version (6.0), only came out in September 3rd 2019.

What’s new

1. Semantic Versioning

The Laravel framework now follows the semantic versioning standards. This makes the framework consistent with the other first-party Laravel packages which already followed this versioning standard. The Laravel release cycle remain unchanged.
What is semantic versioning?
Having the universal way of versioning the software development projects is the best way to track what is going on with the software as new plugins, add-ons, libraries, and extensions are being built almost every day.
Sematic versioning number is divided into 3 parts separated by (.) dot.
[Major Version].[Minor Version].[Patch]
Ex: – Console Version 4.3.2
4- Major Version
3- Minor Version
2- Patch
Major Changes Breaks the API
Minor Changes does not break the API (implementing new features in a backward compatible way)
Patches are bug fixes

2. Ignition Error Page

Ignition is the new default error page for Laravel 6.0

view error whoops

This screen shot is Whoops which is the standard in Laravel 5. It only shows generic info. In stack trace you see that compiled blade view file contains the error, and the view content itself is not readable.

view error ignition

Ignition is a Laravel 6 Specific error page. It displays the un-compiled view path and your blade view.
Also there is a tabs for app, user, context, debug. Read More

3. Improved Authorization Response

Previously it was difficult to provide custom error messages around authorization to end users. Laravel 6 introduces a Gate::inspect() method which provides the authorization policy’s response. This makes it easier to provide custom messages to users during authorization requests, such as specific error message if their request was denied

4. Lazy Collection

To keep memory usage low when dealing with large dataset Laravel introduces lazy collection.
If you are using eloquent models, you can choose to load one model into memory at a time instead of everything at once by using the cursor() method instead of all()
Imagine you need to iterate through 10,000 Eloquent models. When using traditional Laravel collections, all 10,000 Eloquent models must be loaded into memory at the same time:

									$users = App\User::all()->filter(function ($user) {
									    return $user->id > 500;

However, the query builder's cursor method returns a LazyCollection instance. This allows you to still only run a single query against the database but also only keep one Eloquent model loaded in memory at a time. In this example, the filter callback is not executed until we actually iterate over each user individually, allowing for a drastic reduction in memory usage:

									$users = App\User::cursor()->filter(function ($user) {
									    return $user->id > 500;

									foreach ($users as $user) {
									    echo $user->id;

									foreach ($users as $user) {
									    echo $user->id;
5. Eloquent Subquery Enhancement

Subqueries allow you to run nested queries within another database query. This can be a powerful way to retrieve ancillary model data, without making any additional database queries, when it’s not possible to do via a relationship.
The addSelect method has been added to subqueries. Eloquent subqueries will also now have access to orderBy.
Using the subquery functionality available to the select and addSelect methods, we can select all of the destinations and the name of the flight that most recently arrived at that destination using a single query:

									use App\Destination;
									use App\Flight;

									return Destination::addSelect(['last_flight' => Flight::select('name')
									    ->whereColumn('destination_id', '')
									    ->orderBy('arrived_at', 'desc')
6. Laravel UI

The frontend scaffolding provided with Laravel 5.x releases is now extracted into a separate laravel/ui Composer package. This allows first-party UI scaffolding to be iterated on separately from the primary framework.

7. Job Middleware

Job Middleware is a feature contributed by Taylor Otwell, which allows jobs to run through middleware:

									// Add a middleware method to a job class
									public function middleware()
									     return [new SomeMiddleware];

									// Specify middleware when dispatching a job
									SomeJob::dispatch()->through([new SomeMiddleware]);

The middleware will help you avoid custom logic in the body of your job’s handle() method.