dongyin8009 2018-06-19 10:02
浏览 348
已采纳

Laravel 5.6不在`created`模型事件中保存字段

I am trying to save a field from the created model event but for some reason the stripe_coupon_id column is never being saved. The created event does run as I've tested by trying a dd inside it and it does fire the event but just does not save that column.

class DiscountRate extends Model
{
    public $table = "discount_rates";

    public $primaryKey = "id";

    public $timestamps = true;

    public $fillable = [
        'id',
        'name',
        'rate',
        'active',
        'stripe_coupon_id'
    ];



    public static function boot()
        {
            parent::boot();
            self::created(function ($discountRate) {
                $coupon_id = str_slug($discountRate->name);
                $discountRate->stripe_coupon_id = $coupon_id;
            });

        }
}

In my controller I simply call a service function which calls the default Laravel model create function:

public function store(DiscountRateCreateRequest $request)
    {
        $result = $this->service->create($request->except('_token'));

        if ($result) {
            return redirect(route('discount_rates.edit', ['id' => $result->id]))->with('message', 'Successfully created');
        }

    }

discount_rates table:

enter image description here

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 如何抓这个函数的包wx.updateShareMenu
      • ¥15 需要数据分析!时间紧!
      • ¥15 关于免费论文查重系统的问题。
      • ¥15 朋友们,这个sim函数是出了什么问题了呢
      • ¥15 【MRT数据导入问题】MRT处理modis数据提示opening input header file怎么解决?
      • ¥15 嵌入式系统综合设计题有会的教一下嘛?
      • ¥15 yolov5转onnx验证出错
      • ¥15 proteus仿真LCD不点亮
      • ¥15 C语言红绿灯时间问题
      • ¥15 matlab仿真实现定位算法