LoginSignup
5
7

More than 3 years have passed since last update.

Laravel 6.x→7.xバージョンアップ

Posted at

Laravel 6.x→7.xバージョンアップ方法

概要

Laravelのバージョンを6.x→7.xにアップする方法をご紹介します。
基本的には公式ドキュメント様の言う通りです。
なお、今回ご紹介するのはバージョンアップ対応で必要な最低限の項目になります。
詳細は 公式ドキュメント を参照ください。

手順

1. 現在のバージョン確認

% php artisan --version
Laravel Framework 6.18.25

2. composer.jsonの編集

composer.jsonを直接触るのは嫌なのですが、、、公式がそう記載しているので仕方ないですね。

前提

  • Symfony 5以上
  • PHP 7.2.5以上

編集要点

  • laravel/framework: "^7.0"
  • nunomaduro/collision: "^4.1"
  • phpunit/phpunit: "^8.5"
  • laravel/tinker: "^2.0"
  • facade/ignition: "^2.0"

Before

composer.json
{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "ext-fileinfo": "*",
        "barryvdh/laravel-dompdf": "^0.8.5",
        "bensampo/laravel-enum": "^1.28",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "^6.2",
        "laravel/tinker": "^1.0",
        "laravel/ui": "^1.2",
        "nesbot/carbon": "^2.27"
    },
    "require-dev": {
        "barryvdh/laravel-ide-helper": "^2.6",
        "facade/ignition": "^1.4",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

After

composer.json
{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "ext-fileinfo": "*",
        "barryvdh/laravel-dompdf": "^0.8.5",
        "bensampo/laravel-enum": "^1.28",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "^7.0",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^1.2",
        "nesbot/carbon": "^2.27"
    },
    "require-dev": {
        "barryvdh/laravel-ide-helper": "^2.6",
        "facade/ignition": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^8.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

3. App\Exceptions\Handlerの編集

app/Exceptions/Handler.phpを編集します。

編集要点

ExceptionからThrowableに変更します。
注: ちゃんとparentを継承するようにしないと後々エラーになってしまいます。
詳しくはAfterを参照してください。

use Throwable;

public function report(Throwable $exception);
public function shouldReport(Throwable $exception);
public function render($request, Throwable $exception);
public function renderForConsole($output, Throwable $exception);

Before

<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * @param  \Exception  $exception
     * @return void
     */
    public function report(Exception $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {
        return parent::render($request, $exception);
    }
}

After

<?php

namespace App\Exceptions;

use Throwable;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * @param  Throwable  $exception
     * @return void
     */
    public function report(Throwable $exception)
    {
        parent::report($exception);
    }

    public function shouldReport(Throwable $exception)
    {
        parent::shouldntReport($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  Throwable  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Throwable $exception)
    {
        return parent::render($request, $exception);
    }

    public function renderForConsole($output, Throwable $exception)
    {
        parent::renderForConsole($output, $exception);
    }
}

4. sessionファイル編集

app/config/session.phpを編集します。

Before

'secure' => env('SESSION_SECURE_COOKIE', false),

After

'secure' => env('SESSION_SECURE_COOKIE', null),

5. Composer update

% composer update

6. Laravel/uiの設定

composerのrequireセクションにて"2.0"以上が必要なようです。

% composer require laravel/ui "^2.0"

7. 確認

% php artisan --version
Laravel Framework 7.19.1

参考

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7