[Laravel] 5.5から5.6へ3分でアップグレードする方法

既存のLaravel5.5のアプリケーションを5.6へアップグレードする際のまとめです。

細かな変更方法については以下で確認することをお勧めします。

Upgrade Guide - Laravel

※ Laravel5.6の動作には、PHPバージョン7.1.3以上が必要です。

依存パッケージのアップデート

composer.json の以下の内容を変更します。

  • laravel/frameworkの依存指定を5.6.*へ変更
  • fideloper/proxyの依存指定を~4.0へ変更
  • phpunit/phpunitの依存指定を~7.0へ変更

また、公式パッケージのDuskPassportScountを利用している場合は下記も変更します。

  • laravel/duskの依存指定を~3.0へ変更
  • laravel/passportの依存指定を~5.0へ変更
  • laravel/scoutの依存指定を~4.0へ変更

変更したらcomposer updateしましょう。

環境ファイルの変更

.envファイルを変更します。

# .envから削除
APP_LOG
APP_LOG_LEVEL

# .envへ追加
LOG_CHANNEL=stack
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

設定ファイルの変更

config/app.phpから以下の項目を削除しましょう。

'log' => env('APP_LOG', 'single'),

'log_level' => env('APP_LOG_LEVEL', 'debug'),

config/hashing.phpを追加します。

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Hash Driver
    |--------------------------------------------------------------------------
    |
    | This option controls the default hash driver that will be used to hash
    | passwords for your application. By default, the bcrypt algorithm is
    | used; however, you remain free to modify this option if you wish.
    |
    | Supported: "bcrypt", "argon"
    |
    */

    'driver' => 'bcrypt',

];

config/loging.phpを追加します。

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Log Channel
    |--------------------------------------------------------------------------
    |
    | This option defines the default log channel that gets used when writing
    | messages to the logs. The name specified in this option should match
    | one of the channels defined in the "channels" configuration array.
    |
    */

    'default' => env('LOG_CHANNEL', 'stack'),

    /*
    |--------------------------------------------------------------------------
    | Log Channels
    |--------------------------------------------------------------------------
    |
    | Here you may configure the log channels for your application. Out of
    | the box, Laravel uses the Monolog PHP logging library. This gives
    | you a variety of powerful log handlers / formatters to utilize.
    |
    | Available Drivers: "single", "daily", "slack", "syslog",
    |                    "errorlog", "custom", "stack"
    |
    */

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single'],
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
            'days' => 7,
        ],

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Laravel Log',
            'emoji' => ':boom:',
            'level' => 'critical',
        ],

        'syslog' => [
            'driver' => 'syslog',
            'level' => 'debug',
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'level' => 'debug',
        ],
    ],

];

Laravel5.6ではより一層便利なメソッドなどが増えました。積極的にアップデートしていきましょう!

© Xzxzyzyz