laravel 5.3 is planned to be released in June 2016 , this article is a rundown of the considerable number of things you can expect in this release .  currently laravel 5.3 is in development .

Implicit controller routes have been removed

Using Route::controller is no longer available in 5.3, the reasons for that change are stated in Pull Request #10777, here’s part of it:

This method has quite a lot of issues and also makes routes definitions confusing as they are not directly referenced in routes file. This sometimes may lead to unexpected route definitions (e. g. if method like getFilesystem is added to parent or trait – developer mistake, but may be unnoticed).

It’s more likely that this method will be available as a package, so it’s up to you to decide if you’re going to keep using it or switch to using explicit route definitions, however if you decided to switch it’s better to start now.

The Query Builder returns a collection

As of 5.3, the query builder get() method will return an Illuminate\Support\Collection instead of an array. The Pros of such change, as listed by the PR creator, are:

  1. Makes it consistent with Eloquent. You’ll find countless questions on StackOverflow asking why some collection method can’t be called on a query builder result.
  2. It’s just much cleaner than this: collect(DB::table(‘posts’)->get()). Laravel prides itself on making all these tiny interactions more enjoyable. This should not be any different.
  3. Native PHP arrays are just useless.

So if you’re expecting an array out of DB::get() anywhere in your application or tests you’ll need to update your calls to be DB::get()->all() instead.

Removed functions

  • Str::randomBytes and Str::equals are removed in favour of the native PHP methods random_bytes() and hash_equals().
  • The lists() method is also removed from ELoquent Builder, Query Builder, and Collections. You may use the pluck() method directly.
  • array_build() helper is also removed from the framework as it’s no longer used anywhere in the core.
  • Model’s withHidden() method is removed in favour of makeVisible(), same goes for Eloquent Collection’s withHidden(). So in order for you to make certain fields visible after defining them as hidden using the Model’s hidden property, you’ll need to use makeVisible().
  • The Collection::whereLoose() method was removed since Collection::where() now supports operators.

New validate() method in Validator

The new method will throw a ValidationException if the Validations fails, here are the different ways you can use this method:

Using the Validation factory:

$validator = Validator::make($data, $rules);

$validator->validate();

Or on the Validator directly:

Validator::validate($data, $rules);

Or using the helper method:

validator($data, $rules)->validate();

Collection::where() accepts operators

In laravel 5.3 you’re able to filter a collection using where() via operators, and also a major change is that the method performs a loose comparison when not given any operators:

$collection = collect([['score' => '3'], ['score' => 3]]);

// Loose comparison by default
$collection->where('score', 3);
// returns [['score' => '3'], ['score' => 3]]

$collection->where('score', '=', 3);
$collection->where('score', '==', 3);
// returns [['score' => '3'], ['score' => 3]]

$collection->where('score', '===', 3);
// returns [['score' => 3]]

Here’s a list of all the operators you can use:

======<=>=<><>!=!==

With these operators available, the whereLoose() method was removed from the collection class as it’s not needed anymore.

Model::firstOrCreate() accepts additional values

With this change you’ll be able to do something like:

$user = User::firstOrCreate(
    ['github_id', $githubUser->id], 
    ['avatar' => $githubUser->avatar]
);

In case a user with the given github_id was found it’ll be returned, if not a new user will be created with the given github_id and avatar.

 

read full article at themsaid.com

 

Advertisements