[WIP] Finish the order process
This commit is contained in:
@@ -29,10 +29,11 @@ class Customers
|
||||
$name = $customer->first_name . ' ' . $customer->last_name;
|
||||
$avatar = new Avatar();
|
||||
$ret = $avatar->create($name)
|
||||
->setBackground($bgColor)
|
||||
->setBorder(1, '#29292e')
|
||||
->setBackground('#F2B90F')
|
||||
->setForeground('#335012')
|
||||
->setBorder(1, '#28a745')
|
||||
->setFontFamily('Roboto Condensed')
|
||||
->setDimension(40)
|
||||
->setDimension(36)
|
||||
->setFontSize(16)
|
||||
->save($filename);
|
||||
return $ret;
|
||||
@@ -42,7 +43,7 @@ class Customers
|
||||
{
|
||||
$path = storage_path(self::getStorage());
|
||||
if (File::checkDirOrCreate($path)) {
|
||||
$filename = $path . 'user-' . $customer->uuid . '.png';
|
||||
$filename = $path . self::getAvatarFilename($customer);
|
||||
}
|
||||
return $filename ?? false;
|
||||
}
|
||||
@@ -55,58 +56,44 @@ class Customers
|
||||
public static function getAddresses($id = false)
|
||||
{
|
||||
$customer = self::getWithAddresses($id);
|
||||
return $customer ? $customer->addresses : false;
|
||||
}
|
||||
|
||||
public static function getWithAddresses($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
return Customer::with('addresses')->find($id);
|
||||
return self::get($id, 'addresses');
|
||||
}
|
||||
|
||||
public static function getName()
|
||||
public static function getName($id = false)
|
||||
{
|
||||
$user = self::getAuth();
|
||||
return $user ? $user->first_name : '';
|
||||
$user = $id ? self::get($id) : self::getAuth();
|
||||
return $user ? $user->first_name . ' ' . $user->last_name : '';
|
||||
}
|
||||
|
||||
public static function getAuth()
|
||||
{
|
||||
return Auth::guard('customer')->user();
|
||||
return self::guard()->user();
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
return Auth::guard('customer')->id();
|
||||
return self::guard()->id();
|
||||
}
|
||||
|
||||
public static function isConnected()
|
||||
{
|
||||
return Auth::guard('customer')->check();
|
||||
return self::guard()->check();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
public static function get($id = false, $relations = false)
|
||||
{
|
||||
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);
|
||||
$id = $id ? $id : self::getId();
|
||||
return $id ? ($relations ? Customer::with($relations)->findOrFail($id) : Customer::findOrFail($id)) : false;
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
$customer = Customer::with(['addresses'])->find($id);
|
||||
$customer = self::get($id, 'addresses');
|
||||
$data = $customer->toArray();
|
||||
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
|
||||
return $data;
|
||||
@@ -126,9 +113,7 @@ class Customers
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = $data['id'] ?? false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item;
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function storeDeliveries($customer, $deliveries)
|
||||
@@ -166,7 +151,7 @@ class Customers
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
public static function delete($id)
|
||||
{
|
||||
return Customer::destroy($id);
|
||||
}
|
||||
@@ -182,4 +167,9 @@ class Customers
|
||||
$path = '/storage/Customers/';
|
||||
return $filename ? $path . $filename : $path;
|
||||
}
|
||||
|
||||
public static function guard()
|
||||
{
|
||||
return Auth::guard('customer');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user