LoginSignup
6
3

More than 3 years have passed since last update.

Laravel5.5のCarbon1系でaddMinutesメソッドがBadMethodCallException

Last updated at Posted at 2019-08-30

結論

(new Carbon(Carbon::now()))->addMinutes(10)こう記述。
Carbon1系でも動作しますがが非推奨とのことで、Carbon2系にアップデートしましょう。

問題

Carbon::now()->addMinutes(10);

を実行すると

BadMethodCallException with message 'Method addMinutes does not exist.'

Composerを動かすと以下のログが。

Carbon 1 is deprecated, see how to migrate to Carbon 2.
https://carbon.nesbot.com/docs/#api-carbon-2
    You can run './vendor/bin/upgrade-carbon' to get help in updating carbon and other frameworks and libraries that depend on it.

対応

なんか回りくどい書き方

(new Carbon(Carbon::now()))->addMinutes(10);

参考

laravel-carbon-2を参考に、Carbon2系にアップデート

composer.json
{
  ...
  "require": {
    ...
    "kylekatarnls/laravel-carbon-2": "^1.0.0",
    "nesbot/carbon": "2.0.0-beta.2 as 1.25.0"
  }
  ...
}

追加したあと

composer update
6
3
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
6
3