LoginSignup
1
1

More than 5 years have passed since last update.

[Laravel] 5.4 => 5.5 のバージョンアップでハマった点まとめ

Posted at

Model

「updated_at」および「created_at」がテーブルに存在しない時に save() でデータ保存しようとするとエラーになる

エラー内容

ArgumentCountError: Too few arguments to function Illuminate\Database\Eloquent\Model::setAttribute(), 1 passed in /home/livede55.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php on line 525 and exactly 2 expected

setAttribute() が呼ばれているが引数が足りないよ
と怒られてしまう

原因

updated_at および created_at が存在しないテーブルなのでEloquentの設定は以下にしている

const CREATED_AT = null;
const UPDATED_AT = null;

この状態で何故か 5.5 になると updated_at および created_at に対しての setAttribute() が動作し、
カラム名が null なので 引数エラーが起こる

本家LaravelのGitHubにもIssueが作成されている

対応

Issueにハックが記載されている対応を行う

public function setUpdatedAt($value)
{
    return $this;
}

public function setCreatedAt($value)
{
    return $this;
}

setAttribute() 呼び出しされる前提で updated_at および created_at のミューテターを定義してあげる

1
1
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
1
1