LoginSignup
0
0

More than 5 years have passed since last update.

laravel で Illuminate/Database/Eloquent/MassAssignmentException エラーが出るとき

Posted at

laravel でUPDATAしようとしたときに以下のエラーが出たため、対策を残しておきます。

Illuminate/Database/Eloquent/MassAssignmentException with message

環境
cloud9のPHP環境を使用
PHP: 7.x
laravel: 5.x
MySQL: x.x
Webサーバー: apatch

対策
PJ名 > app > テーブル名.phpファイルを編集します。

Post.php(befor)
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    //
}

Postテーブルの title と body のカラムにはデータを登録しても良いという設定をしています。

Post.php(after)
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    //

    //MassAssignmentException 対策
    protected $fillable = ['title', 'body'];
}

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