1,创建模型
php artisan make:model Book -m
创建模型book 并生成迁移文件
2,Book迁移文件
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->decimal('price');
$table->integer('num');
$table->timestamps();
});
}
php artisan migrate
生成迁移文件
3,控制器使用模型
public function testSql(){
Book::create([
'title'=>'图书一',
'price'=>1.23,
'num'=>23,
]);
}
4,模型设置字段
protected $fillable=['title','price','num'];标签:Laravel,function,num,title,模型,Book,简单,table From: https://www.cnblogs.com/96net/p/17811140.html