Laravel技巧集锦(五):使用Model::create快速插入数据

孙志
2023-12-01

1、Model中设置

class Post extends Model
{
    //set the table
    //protected $table = '';

    //allow array 
    protected $fillable = ['title','content']; //allowed 
    //protected $guarded = [];                    //not allowed (if empty -> any allow)

}

2、控制器中使用

Post::create(\request(['title','content']));

 

 类似资料: