Laravel Eloquent - $fillable is not working?

后端 未结 4 758
天涯浪人
天涯浪人 2020-12-11 09:28

I have set the variable $fillable in my model. I wanted to test the update functionality, and I get this error:

SQLSTATE[42S

4条回答
  •  [愿得一人]
    2020-12-11 09:48

    write a parent class

    class BaseModel extends Model
    
    public static function getFillableAttribute(Model $model, $data){
        $array = $model->getFillable();
        $arr = [];
        foreach ($array as $item){
            if( isset($data["$item"])){
                $arr["$item"] = $data["$item"];
            }
        }
        return $arr;
    }
    

提交回复
热议问题