diff --git a/app/Models/Shop/Customer.php b/app/Models/Shop/Customer.php index 715fa700..82a00bc3 100644 --- a/app/Models/Shop/Customer.php +++ b/app/Models/Shop/Customer.php @@ -9,7 +9,7 @@ class Customer extends Model protected $guarded = ['id']; protected $table = 'shop_customers'; - public function CustomerAddresses() + public function addresses() { return $this->hasMany(CustomerAddress::class); } @@ -26,7 +26,7 @@ class Customer extends Model public function deliveries() { - return $this->belongsToMany(Delivery::class); + return $this->belongsToMany(Delivery::class, 'shop_customer_deliveries'); } public function deliveries2() diff --git a/app/Models/Shop/CustomerAddress.php b/app/Models/Shop/CustomerAddress.php index 06fcba6f..24e644eb 100644 --- a/app/Models/Shop/CustomerAddress.php +++ b/app/Models/Shop/CustomerAddress.php @@ -7,13 +7,14 @@ use Illuminate\Database\Eloquent\Model; class CustomerAddress extends Model { protected $guarded = ['id']; + protected $table = 'shop_customer_addresses'; - public function Customer() + public function customer() { return $this->belongsTo(Customer::class); } - public function Orders() + public function orders() { return $this->hasMany(Order::class); } diff --git a/app/Repositories/Shop/Customers.php b/app/Repositories/Shop/Customers.php index 686b2480..065d4131 100644 --- a/app/Repositories/Shop/Customers.php +++ b/app/Repositories/Shop/Customers.php @@ -28,15 +28,10 @@ class Customers public static function storeFull($data) { - dump($data); - exit; - $deliveries = $data['deliveries']; $addresses = $data['addresses']; unset($data['deliveries']); unset($data['addresses']); - dump($data); - exit; $customer = self::store($data); self::storeDeliveries($customer, $deliveries); self::storeAddresses($customer, $addresses); @@ -47,7 +42,7 @@ class Customers { $id = $data['id'] ?? false; $item = $id ? self::update($data, $id) : self::create($data); - return $item->id; + return $item; } public static function storeDeliveries($customer, $deliveries) @@ -67,6 +62,7 @@ class Customers public static function storeAddresses($customer, $addresses) { foreach ($addresses as $address) { + $address['customer_id'] = $customer->id; CustomerAddresses::store($address); } }