初心者から職人になりたくて、fill使ったらエラーが起きて、エラー文でぐぐってもよくわからず、fillメソッド軽くソース読んだら$fillableに、保存したいcolumn名を入れないといけないみたい。
と思ったところでドキュメント読んだらちゃんと書いてあった。
まず、ドキュメントを読んで、わからなければソースを見るのがいいみたい。
// error
Add [_token] to fillable property to allow mass assignment on
// このエラーとのときは、fillableを指定する
protected $fillable = ['hoge', 'fuga'];
// error ?? このときは、columnに足りないのをつけたす。
SQLSTATE[HY000]: General error: 1364 Field
// add
protected $fillable = ['hoge', 'fuga', 'piyo'];
<?php
namespace Illuminate\Database\Eloquent\Concerns;
use Illuminate\Support\Str;
trait GuardsAttributes
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [];
参考
LaravelのORMで初心者から職人へ
https://qiita.com/henriquebremenkanp/items/cd13944b0281297217a9
laravel/framework
framework/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php
Laravel 5.5 Eloquent:利用の開始
複数代入
https://readouble.com/laravel/5.5/ja/eloquent.html#mass-assignment