Note: Laravel8 Release & Upgrade

Sep 8, 2020 PHP Laravel

Released on 09/08/2020. The bug fix period will be 2021 / 03/08, and the security fix will be until 2021 / 09/08.

And although the amount of upgrades is small due to the large number of new features, it is a little tricky if you are using the factory. (Because the behavior when migrate is done after doing schema: dump of migration seems to be scary, please do it at your own risk)

If you want to see the update for the upgrade in source code units, you can see Github comparision tool.

Personal note: When upgrading, it’s a good idea to use phpstan for static analysis.

[New] Laravel Jetstream

see: https://github.com/laravel/jetstream

It’s a new package.

Use Scaffolding’s livewireorInertiatofeellikeVueorTailwindCSS.com/) Use it like …?

I don’t understand this at all. I wonder if the management screen without the blade is automatically created.

[New] Model Directory

The initial position of the Eloquent Model is now in app / Models.

[New] Model Factory Classes

factory is now a class. For example, if the User factory used to be a solid PHP script, it will be specified in the class.

If you use the old Factory, you will use laravel / legacy-factories. We recommend rewriting as much as possible.

<? php
/ ** @var \ Illuminate \ Database \ Eloquent \ Factory $ factory * /

use Faker \ Generator as Faker;

$ factory-> define (\ App \ Eloquent \ User :: class, function (Faker $ faker) {
    return [
            'name' => $ this-> faker-> name,
            'email' => $ this-> faker-> unique ()-> safeEmail,
            'email_verified_at' => now (),
            'password' =>'$ 2y $ 10 $ 92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC / .og / at2.uheWG / igi', // password
            'remember_token' => Str :: random (10),
    ];;
});

new::

<? php

namespace Database \ Factories;

use App \ Models \ User;
use Illuminate \ Database \ Eloquent \ Factories \ Factory;
use Illuminate \ Support \ Str;

class UserFactory extends Factory
{
    / **
     * The name of the factory's corresponding model.
     *
     * @var string
     * /
    protected $ model = User :: class;

    / **
     * Define the model's default state.
     *
     * @return array
     * /
    public function definition ()
    {
        return [
            'name' => $ this-> faker-> name,
            'email' => $ this-> faker-> unique ()-> safeEmail,
            'email_verified_at' => now (),
            'password' =>'$ 2y $ 10 $ 92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC / .og / at2.uheWG / igi', // password
            'remember_token' => Str :: random (10),
        ];;
    }
}

Along with this, it seems that a factory will be created from the Eloquent side.

<? php

use App \ Model \ User;

User :: factory ()-> count (50)-> create ();

[New] Migration Squash

You will be able to output a schema written in SQL. The output schema is saved in database / schema.

It is also involved in migration. (later)

php artisan schema: dump

[New] Job Batching

Batch processing is added by Bus, and it seems that it can be used in a writing style like axios.

<? php
use App \ Jobs \ ProcessPodcast;
use App \ Podcast;
use Illuminate \ Bus \ Batch;
use Illuminate \ Support \ Facades \ Batch;
use Throwable;

$ batch = Bus :: batch ([[
    new Process Podcast (Podcast :: find (1)),
    new Process Podcast (Podcast :: find (2)),
    new Process Podcast (Podcast :: find (3)),
    new Process Podcast (Podcast :: find (4)),
    new Process Podcast (Podcast :: find (5)),
])-> then (function (Batch $ batch) {
    // All jobs completed successfully ...
})-> catch (function (Batch $ batch, Throwable $ e) {
    // First batch job failure detected ...
})-> finally (function (Batch $ batch) {
    // The batch has finished executing ...
})-> dispatch ();

return $ batch-> id;

[New] Improved Rate Limit

The Requtest Rate Limit is controlled by throttle middleware, but it seems that the rate limit can be changed a little more flexibly.

For example, if there is no rate limit for member users and the rate limit is set to 100 times / minute otherwise, it seems that it can be changed as follows.

<? php
use Illuminate \ Cache \ RateLimiting \ Limit;
use Illuminate \ Support \ Facades \ RateLimiter;


// Probably set in AppServiceProvider
RateLimiter :: for ('uploads', function (Request $ request) {
    return $ request-> user ()-> vipCustomer ()
                ? Limit :: none ()
                : Limit :: perMinute (100);
});

It seems that it can be used by specifying it with throttole of middleware.

Route :: middleware (['throttle: uploads'])-> group (function () {
  Route :: post ('/ audio', function () {});
  
  Route :: post ('/ video', function () {});
});

[New] Improved Maintenance Mode

The behavior when entering maintenance mode with php artisan down.

  1. –secret = ‘1630542a-246b-4b66-afa1-dd72a4c43515’

Using this option will redirect users who come to / to /1630542a-246b-4b66-afa1-dd72a4c43515.

  1. –render ='errors :: 503’

By using this option, you can specify the template to be displayed.

[New] Closure Dispatch / Chain

You can now do -> catch (function () {}) in dispatch helper. Probably the same reasoning as Bus above.

<? php

use Throwable;

dispatch (function () use ($ podcast) {
    $ podcast-> publish ();
})-> catch (function (Throwable $ e) {
    // This job has failed ...
});

[New] Dynamic Blade Components

You can use it by writing the component registered with Blade :: component ('package-alert', AlertComponent :: class); as <x-package-alert /> on the template side.

It seems that the class name is written in camelCase and the component name is written in kebab-case.

Component Methods

You can run methods within the component template.

/ **
 * Determine if the given option is the current selected option.
 *
 * @param string $ option
 * @return bool
 * /public function isSelected ($ option)
{
    return $ option === $ this-> selected;
}
<option {{$ isSelected ($ value)?'selected = "selected"':''}} value = "{{$ value}}">
    {{$ label}}
</ option </ option

(Vaguely like something like vue)

[New] Event Listener Improvements

You can decorate to use Queue when doing \ Event :: listen in Facade.

use App \ Events \ PodcastProcessed;
use function Illuminate \ Events \ queueable;
use Illuminate \ Support \ Facades \ Event;

Event :: listen (queueable (function (PodcastProcessed $ event) {
    // //
}));

And you can make it finer like queue job and you can make a-> catch chain.


Event :: listen (queueable (function (PodcastProcessed $ event) {
    // //
})-> catch (function (PodcastProcessed $ event, Throwable $ e) {
    // The queued listener failed ...
})-> onConnection ('redis')
  -> onQueue ('podcasts')
  -> delay (now ()-> addSeconds (10))
);

[New] Time Testing Helpers

You can specify the time to return with Carbon :: now ().

[New] Artisan serve Improvements

If you update the .env file, artisan serve will automatically reread the settings.

[New] Tailwind Pagination Views

Tailwind can be used as a Pagination template in addition to Bootstrap3 and Bootstrap4.

[Upgrade] Package dependent

If you are using other packages, please update them as well

[Upgrade] [Medium] Use PHP> = 7.3.0

Please specify 7.3.0 or higher for PHP depending on the circumstances.

[Upgrade] [Low] isset method

The behavior of offsetExists in Illuminate \ Support \ Collection has changed. Therefore, the behavior when confirmed with isset changes.

<? php

$ collection = collect ([null]);

// Laravel 7.x --true
isset ($ collection [0]);

// Laravel 8.x --false
isset ($ collection [0]);

[Upgrade] [High] Model Factories

model factories have been classified. If you want to continue using without Rewrite factory up to 7.x, use laravel / legacy-factory. You need to use it.

[Upgrade] [Low] The Castable Interface

The type specification of array has been added to the argument $ arguments of castUsing of Castable, so please add it.

[Upgrade] [Low] Increment / Decrement Events

The increment, decrement instance methods work when the model update and save work.

[Upgrade] [Low] The Dispatcher Contract

The standard value of the second argument $ listener of the listen method of Illuminate \ Contracts \ Events \ Dispatcher has been added with null.

public function listen ($ events, $ listener = null);

[Upgrade] [Optional] Mentenance Mode Updates

Please update public / index.php if you want to use the new features such as --render. This conditional branch line must be written directly under LARAVEL_START.

<? php
define ('LARAVEL_START', microtime (true));

if (file_exists (__DIR__.'/../storage/framework/maintenance.php')) {
    require __DIR__.'/../storage/framework/maintenance.php';
}

[Upgrade] [Low] Manager $ app Property

The $ app property of the Illuminate \ Support \ Manager class has disappeared. If you are using that property, use the $ container property.

[Upgrade] [Low] The elixir Helper

The elixir helper has been removed. Please move to Laravel Mix.

[Upgrade] [Low] Mail :: sendNow Method

The sendNow method in the Mail facade has been removed. Use the send method.

[Upgrade] [High] Pagination Defaults

Paginate’s standard template is now Tailwind CSS (https://tailwindcss.com/). If you want to continue using your existing BootStrap, enter \ Illuminate \ Pagination \ Paginator :: useBootstrap (); in the boot method of AppServiceProvider.

[Upgrade] [High] Queue :: retryAfter method / property

The retryAfter methods and retryAfter properties in QueuedJob, Mailer, Notification, and Listener have been renamed to backoff.

[Upgrade] [High] Queue :: timeoutAt property

The timeoutAt property of QueueJob, Notification, Listener is now retryUntil.

[Upgrade] [Optional] Failed Jobs Table Batch Support

The uuid field is required when queue_driver is using failed_jobs with database.

<? php
use Illuminate \ Database \ Schema \ Blueprint;
use Illuminate \ Support \ Facades \ Schema;

Schema :: table ('failed_jobs', function (Blueprint $ table) {
    $ table-> string ('uuid')-> after ('id')-> unique ();
});

Then place database-uuids in failed.driver of queue.php.

[Upgrade] [Low] The cron-expression Library

The version of dragonmantank / cron-expression used to parse the Cron format has been updated to 3.x. If you write it poorly, it will move at an unintended time, so look at Changelog. You need to confirm.

[Upgrade] [Low] The Session Contract

The \ Session :: pull () method has been added.

/ **
  * Get the value of a given key and then forget it.
  *
  * @param string $ key
  * @param mixed $ default
  * @return mixed
  * /
 public function pull ($ key, $ default = null);

[Upgrade] [Medium] Testing, The assertExactJson Method

The assertExactJson method now checks that the numeric keys are in the same order. If you don’t mind the order, use assertSimilarJson.

Vague :: What is this?

$ asset = [0 => 1, 1 => 1, 2 => 1];
$ data = ['1' => 1, '0' => 1, '2' => 1];$this->assertExactJson(json_encode($asset), json_encode($data)) // => false
$this->assertSimilarJson(json_encode($asset), json_encode($data)) // => true
```

# [Upgrade][Low] Database Rule Connections

`unique`,`exists` ルールに `getConnectionName` メソッドが追加されました。