I have this on my model
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();
});
}
normal post process it saves on my activity table but when i do ajax call i wont and it does not have errors . please help me out on this
Anytime I need to use ajax in Laravel, I write an app-dependent API for using Ajax. Truthfully, Laravel uses an MVC style architecture, and following those guidelines, only a controller should interact with a model. My suggestion would be to write a route that the ajax call makes a request to, and use that controller method tied to the route to handle the ajax call, and save information to the DB with your model.