Laravel Dynamic Fillable in Models

前端 未结 3 2089
执笔经年
执笔经年 2020-12-31 19:45

Got stuck in a issue with laravel 5.2.

Following is the error during eloquent create operation(post call),

Mass Assignment Exception in Model.php 453: column

3条回答
  •  爱一瞬间的悲伤
    2020-12-31 20:29

    Try this. Put the below code in your model,

    public function __construct()
    {
        $this->setFillable();
    }
    public function setFillable()
    {
        $fields = \Schema::getColumnListing('table_name_here');
    
        $this->fillable[] = $fields;
    }
    

    This makes each and every column is fillable from that table.

提交回复
热议问题