我的型号上有这个
public static function boot()
{
// there is some logic in this method, so don't forget this!
parent::boot();
Deal::created(function ($deal) {
// or something
$merchant = Deal::find($deal->deal_id)->merchant;
$activity = new Activity;
$activity->doer_id = $merchant->merchant_id;
$activity->doer_name = $merchant->merchant_name;
$activity->event_type= $merchant->merchant_name. " posted ".$deal->deal_name;
$activity->save();
});
Deal::updated(function ($deal) {
$merchant = Deal::find($deal->deal_id)->merchant;
$activity = new Activity;
$activity->doer_id = $merchant->merchant_id;
$activity->doer_name = $merchant->merchant_name;
if($$deal->deal_status == 1){
$activity->event_type= $deal->deal_name. " was approved ";
}else{
$activity->event_type= $deal->deal_name. " was rejected ";
}
$activity->save();
});
}
正常的后期处理会保存在我的活动表上,但当我调用ajax时,我不会这样做,也没有错误。请帮我处理这个
每当我需要在Laravel中使用ajax时,我都会编写一个依赖于应用程序的API来使用ajax。事实上,Laravel使用MVC风格的架构,并且遵循这些准则,只有控制器才能与模型交互。我的建议是编写一个ajax调用向其发出请求的路由,并使用与该路由绑定的控制器方法来处理ajax调用,并将信息与模型一起保存到DB中。