hasMany(Participation::class, 'customer_id'); } // * METHODS /** * Check if user is admin. * ! Not local CRM ! * * @return boolean */ public function isAdmin(): bool { return false; } /** * Check if user is local. * ! Not local CRM ! * * @return boolean */ public function isLocal(): bool { return false; } /** * Get the crm Data of a customer * * @return \LDC\LDCCRM\Models\Customer * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response. * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs. * Possibles are : - modelNotFound, If this customer hashcode could not be found. * @author Jérémy Munsch * @phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.WrongNumber */ public function getApiDataAttribute(): CrmCustomer { /** @var \LDC\LDCCRM\CrmApiV2 */ $crm = app('crmAPI'); $crmCustomer = $crm->getCustomer($this->hashcode); if (!$crmCustomer) { throw new CrmException('CRM get Customer returned null'); } return $crmCustomer; } /** * This mutate Customer attributes to array * including only non critical properties and crm values * (One that can be send to front office without security breach) * * @return array */ public function toArray() { if ($this->hashcode) { return collect(array_merge( parent::toArray(), (array)$this->apiData ))->intersectByKeys([ 'email' => '', 'firstname' => '', 'lastname' => '', 'address' => '', 'address2' => '', 'postcode' => '', 'birth_date' => '', 'city' => '', 'country' => '', 'opt_in' => '', 'phone' => '' ])->toArray(); } else { return parent::toArray(); } } }