/** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); Contact::updating(function (Contact $contact) { if ($new_values = $contact->getDirty()) { if (isset($new_values['status'])) { $message = \Lang::get('contact.status_update.' . $new_values['status']); if ($contact->hasAttribute('change_status_comment')) { if ($comment = $contact->getAttribute('change_status_comment')) { $message .= PHP_EOL . $comment; } unset($contact->change_status_comment); } } else { $values = []; $old_values = $contact->getOriginal(); foreach ($new_values as $key => $value) { $values[] = [$key, $old_values[$key], $value]; } $message = 'json:' . json_encode($values); } $log = new ContactLog(); $log->contact_id = $contact->id; $log->user_id = \Auth::getUser()->id; $log->comment = $message; $log->save(); } }); }
/** * Добавить коммент * * @param \Illuminate\Http\Request $request * @param $id * @return \Illuminate\Http\Response */ public function store(Request $request, $id) { $contact = \App\Contact::findOrFail($id); $data = $request->input(); $validator = \Validator::make($data, $rules = self::getValidatorRules()); if (!$validator->fails()) { $model = new ContactLog($request->input()); $model->user_id = \Auth::getUser()->id; $model->contact_id = $contact->id; $model->save(); } return redirect(route('contact.show', $contact)); }