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 のミューテターを定義してあげる