From 5ccc9eba4cd87649de857fa38ed177bbc9ec4644 Mon Sep 17 00:00:00 2001 From: harshjagad20 Date: Sat, 22 May 2021 13:24:10 +0530 Subject: [PATCH] Helper for custom field to get by slug --- app/Models/Invoice.php | 5 +++++ app/Traits/HasCustomFieldsTrait.php | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index dc4f8469..45c3dcf8 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -591,4 +591,9 @@ class Invoice extends Model implements HasMedia '{INVOICE_LINK}' => url('/customer/invoices/pdf/'.$this->unique_hash), ]; } + + public function getValues($slug) + { + return $this->getCustomFieldValues($slug); + } } diff --git a/app/Traits/HasCustomFieldsTrait.php b/app/Traits/HasCustomFieldsTrait.php index f7de7aa0..7617f16c 100644 --- a/app/Traits/HasCustomFieldsTrait.php +++ b/app/Traits/HasCustomFieldsTrait.php @@ -42,4 +42,11 @@ trait HasCustomFieldsTrait $customFieldValue->save(); } } + + public function getCustomFieldValues($slug) + { + return $this->fields()->whereHas('customField', function ($query) use ($slug) { + $query->where('slug', $slug); + })->first(); + } }