'required|integer|exists:accounts,id', 'contact_id' => 'required|integer|exists:contacts,id', 'author_id' => 'required|integer|exists:users,id', 'description' => 'nullable|string|max:255', ]; } /** * Set a contact's description. * The description should be saved as unparsed markdown content, and fetched * as unparsed markdown content. The UI is responsible for parsing and * displaying the proper content. * * @param array $data * @return Contact */ public function execute(array $data): Contact { $this->validate($data); /** @var Contact $contact */ $contact = Contact::where('account_id', $data['account_id']) ->findOrFail($data['contact_id']); $contact->throwInactive(); $contact->description = $data['description']; $contact->save(); $this->log($data, $contact); return $contact->refresh(); } /** * Add an audit log. * * @param array $data * @param Contact $contact * @return void */ private function log(array $data, Contact $contact): void { $author = User::find($data['author_id']); LogAccountAudit::dispatch([ 'action' => 'contact_description_updated', 'account_id' => $author->account_id, 'about_contact_id' => $contact->id, 'author_id' => $author->id, 'author_name' => $author->name, 'audited_at' => now(), 'should_appear_on_dashboard' => true, 'objects' => json_encode([ 'contact_name' => $contact->name, 'contact_id' => $contact->id, ]), ]); } }