我在控制器中使用最新的Laravel和以下代码:
function changeProperty(Request $request){
if(Car::find('id', 34)->save(array('expired' => true))){
return [
'success' => true,
'check' => Car::find(34)
];
}
return [
'success' => false
];
}
Run Code Online (Sandbox Code Playgroud)
我得到了success => true,但是当我签入PHPMyAdmin时,该值未保存。在中,Property::find(34)我看到Car被选中,但也没有更新值expired,默认情况下为0。
这是Car模型的一部分:
protected $fillable = [
'expired'
];
Run Code Online (Sandbox Code Playgroud)
这是cars表的迁移:
public function up()
{
Schema::create('cars', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->boolean('expired')->default(false);
$table->timestamps();
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27 次 |
| 最近记录: |