【问题标题】:Laravel doesn't save, but returns trueLaravel 不保存,但返回 true
【发布时间】:2019-05-11 23:23:29
【问题描述】:

我在控制器中使用最新的 Laravel 和这段代码:

function changeProperty(Request $request){

    if(Car::find('id', 34)->save(array('expired' => true))){
        return [
            'success' => true,
            'check' => Car::find(34)
        ];
    }

    return [
        'success' => false
    ];
}

我收到success => true,但是当我签入 PHPMyAdmin 时,该值没有保存。 在Property::find(34) 中,我看到选择了 Car,但也没有更新值 expired,默认为 0。

这是Car 模型的一部分:

protected $fillable = [
    'expired'
];

这是汽车表的迁移:

    public function up()
{
    Schema::create('cars', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->boolean('expired')->default(false);
        $table->timestamps();
    });
}

【问题讨论】:

    标签: laravel laravel-5


    【解决方案1】:

    应该是:

    Car::find('id', 34)->update($params)
    

    save() 不接受属性作为参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 2016-02-22
      • 2015-03-03
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      相关资源
      最近更新 更多