contact_repo = $contact_repo; } /** * Gets the class name. * * @return string The class name. */ public function getClassName() { return Client::class; } /** * Saves the client and its contacts * * @param array $data The data * @param \App\Models\Client $client The client * * @return Client|\App\Models\Client|null Client Object */ public function save(array $data, Client $client) : ?Client { \Log::error($data); $client->fill($data); $client->save(); if ($client->id_number == "" || !$client->id_number) { $client->id_number = $this->getNextClientNumber($client); } //todo write tests for this and make sure that custom client numbers also works as expected from here $client->save(); // \Log::error($client); if (isset($data['contacts'])) { $contacts = $this->contact_repo->save($data['contacts'], $client); } if (empty($data['name'])) { $data['name'] = $client->present()->name(); } return $client; } /** * Store clients in bulk. * * @param array $client * @return Client|null */ public function create($client): ?Client { return $this->save( $client, ClientFactory::create(auth()->user()->company()->id, auth()->user()->id) ); } }