From 46f8c44fff14acd3bfd0531010b0b2e78eb5d864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Wed, 22 Jan 2020 21:24:00 +0300 Subject: [PATCH] Set contact types (customer/vendor) --- app/Traits/Contacts.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/Traits/Contacts.php b/app/Traits/Contacts.php index 8c396e972..35b40959e 100644 --- a/app/Traits/Contacts.php +++ b/app/Traits/Contacts.php @@ -17,4 +17,29 @@ trait Contacts return ($return == 'array') ? explode(',', $types) : $types; } + + public function setCustomerType($new_type) + { + $this->setType($new_type, 'customer'); + } + + public function setVendorType($new_type) + { + $this->setType($new_type, 'vendor'); + } + + public function setType($new_type, $index) + { + $types = explode(',', setting('contact.type.' . $index, $index)); + + if (in_array($new_type, $types)) { + return; + } + + $types[] = $new_type; + + setting([ + 'contact.type.' . $index => implode(',', $types), + ])->save(); + } }