Content Source:
The Laravel team released the 400th release of Laravel (v5.8.12) recently with a new duplicates() collection method and other new features, fixes, and changes to the framework.
First, a new duplicates() method was added to the Illuminate\Support\Collection class:
collect([1,2,1,1,1])->duplicates(); => Illuminate\Support\Collection {#2938 all: [ 2 => 1, 3 => 1, 4 => 1, ], }
It works by returning the indexes of the duplicate values from the original collection object:
$item[0] = 1 is not a duplicate $item[1] = 2 is not a duplicate $item[2] = 1 is a duplicate $item[3] = 1 is a duplicate $item[4] = 1 is a duplicate
Similarly, a new duplicates() method was added to the Eloquent collection class, using the $model->is($another) to check for duplicates. Here’s an example from PR #28194:
use App\User; $one = User::find(1); $two = User::find(1); $three = User::find(1); $users = (new User)->newCollection([$one, $two, $three]); => Illuminate\Database\Eloquent\Collection {#2936 all: [ 1 => App\User {#2929 id: "1", name: "Admin", email: "admin@example.com", email_verified_at: null, created_at: "2019-04-16 23:33:30", updated_at: "2019-04-16 23:33:30", }, 2 => App\User {#2927 id: "1", name: "Admin", email: "admin@example.com", email_verified_at: null, created_at: "2019-04-16 23:33:30", updated_at: "2019-04-16 23:33:30", }, ], }
Next, a new getViews() method was added to the FileViewFinder class, which allows you to retrieve all the view information from currently loaded views. Nothing is new here except the ability to access the $views property via the getViews() method.
As of Laravel 5.8.11, the exit code is captured in scheduled command events, which lead to a new PR providing some helpers available to the scheduler:
$schedule->command('my:command') ->onSuccess(function () { // do something when scheduled command ran successfully }) ->onFailure(function () { // do something when scheduled command failed }) ->pingOnSuccess('https://example.com') ->pingOnFailure('https://example.com') ->emailOnFailure('johndoe@example.com') ;
The emailOnFailure() method is useful when you only want to receive an email for failed scheduled commands as opposed to the emailOutputTo method which is sent no matter what the outcome of the scheduled task. The new scheduler methods have already been added to the scheduling documentation.
Next, the SET datatype was added to the MySQL grammar (learn more about The SET Type):
Schema::create('table_name', function (Blueprint $table) { $table->bigIncrements('id'); $table->set("field_name", [ "Possible", "Values" ]); $table->timestamps(); });
The last new feature in this release is the addition of the in and not in operators, which can be passed as strings to the query builder:
// these two calls produce the same query $query->where('foo', 'in', [1, 2]); $query->whereIn('foo', [1, 2]); // these two calls produce the same query $query->where('foo', 'not in', [1, 2]); $query->whereNotIn('foo', [1, 2]);
You can see the full list of fixes below, and the whole diff between 5.8.11 and 5.8.12 on GitHub. The full release notes for Laravel 5.8 are available in the GitHub 5.8 changelog:
v5.8.12
Added
- Added Illuminate\Support\Collection::duplicates()
- Added Illuminate\Database\Eloquent\Collection::duplicates()
- Added Illuminate\View\FileViewFinder::getViews()
- Added helper methods onSuccess() \ onFailure() \ pingOnSuccess() \ pingOnFailure() \ emailOnFailure() to Illuminate\Console\Scheduling\Event
- Added SET datatype on MySQL Grammar
- Added possibility for use in / not in operators in the query builder
Fixed
- Fixed memory leak in JOIN queries
- Fixed circular dependency in Support\Testing\Fakes\QueueFake for undefined methods
- Fixed exception in lt \ lte \ gt \ gte validations with different types
- Fixed string quoting for SQL Server
- Fixed whereDay and whereMonth when passing int values
Changed
- Added autocomplete attributes to the html stubs
- Improved event:list command
- Updated Illuminate\Database\Console\Factories\FactoryMakeCommand to generate more IDE friendly code
- Added missing LockProvider interface on DynamoDbStore
- Change session’s user_id to unsigned big integer in the stub
For more Information and to build a website using Laravel, Hire Laravel Developer from us as we give you a high-quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft“.
To develop the custom website using Laravel, please visit our technology page
- laravel-news.com