first_name . ' ' . $customer->last_name; $avatar = new Avatar(); $ret = $avatar->create($name) ->setBackground($bgColor) ->setBorder(1, '#29292e') ->setFontFamily('Roboto Condensed') ->setDimension(40) ->setFontSize(16) ->save($filename); return $ret; } public static function makeAvatarFilename($customer) { $path = storage_path(self::getStorage()); if (File::checkDirOrCreate($path)) { $filename = $path . 'user-' . $customer->uuid . '.png'; } return $filename ?? false; } public static function getAvatarFilename($customer) { return 'user-' . $customer->uuid . '.png'; } public static function getAddresses($id = false) { $customer = self::getWithAddresses($id); } public static function getWithAddresses($id = false) { $id = $id ? $id : self::getId(); return Customer::with('addresses')->find($id); } public static function getName() { $user = self::getAuth(); return $user ? $user->first_name : ''; } public static function getAuth() { return Auth::guard('customer')->user(); } public static function getId() { return Auth::guard('customer')->id(); } public static function isConnected() { return Auth::guard('customer')->check(); } public static function getOptions() { return Customer::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray(); } public static function getOptionsByPackage($package_id) { return Customer::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray(); } public static function getAll() { return Customer::orderBy('value', 'asc')->get(); } public static function get($id) { return Customer::find($id); } public static function edit($id) { $customer = Customer::with(['addresses'])->find($id); $data = $customer->toArray(); $data['deliveries'] = $customer->deliveries->pluck('id')->toArray(); return $data; } public static function storeFull($data) { $deliveries = $data['deliveries']; $addresses = $data['addresses']; unset($data['deliveries']); unset($data['addresses']); $customer = self::store($data); self::storeDeliveries($customer, $deliveries); self::storeAddresses($customer, $addresses); return $customer->id; } public static function store($data) { $id = $data['id'] ?? false; $item = $id ? self::update($data, $id) : self::create($data); return $item; } public static function storeDeliveries($customer, $deliveries) { if (!$deliveries) { return false; } $deliveries = collect($deliveries)->transform( function ($item, $key) { return (int) $item; } )->toArray(); return $customer->deliveries()->sync($deliveries); } public static function storeAddresses($customer, $addresses) { foreach ($addresses as $address) { $address['customer_id'] = $customer->id; CustomerAddresses::store($address); } } public static function create($data) { $data['uuid'] = Str::uuid()->toString(); return Customer::create($data); } public static function update($data, $id = false) { $id = $id ? $id : $data['id']; $customer = self::get($id); $customer->update($data); return $customer; } public static function destroy($id) { return Customer::destroy($id); } public static function getStorage($filename = false) { $path = '/app/public/Customers/'; return $filename ? $path . $filename : $path; } public static function getPublic($filename = false) { $path = '/storage/Customers/'; return $filename ? $path . $filename : $path; } }