From b45cec0200d4421a24f701ff1918684685dc9282 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Mon, 27 Nov 2023 11:47:26 +0500 Subject: [PATCH] wip --- app/Nova/Resources/Order/Loan/LoanOrder.php | 1 - app/Repos/Order/Loan/BranchRepo.php | 44 ++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/Nova/Resources/Order/Loan/LoanOrder.php b/app/Nova/Resources/Order/Loan/LoanOrder.php index 9458603..8c84298 100644 --- a/app/Nova/Resources/Order/Loan/LoanOrder.php +++ b/app/Nova/Resources/Order/Loan/LoanOrder.php @@ -128,7 +128,6 @@ class LoanOrder extends Resource Select::make(__('Branch'), 'branch_id') ->displayUsingLabels() ->searchable() - ->options(BranchRepo::values()) ->dependsOn('region', BranchNovaRepo::dependsOnRegion()) ->size('w-1/2') ->rules('required') diff --git a/app/Repos/Order/Loan/BranchRepo.php b/app/Repos/Order/Loan/BranchRepo.php index 34dca53..70ef4cd 100644 --- a/app/Repos/Order/Loan/BranchRepo.php +++ b/app/Repos/Order/Loan/BranchRepo.php @@ -7,11 +7,53 @@ use Illuminate\Support\Collection; class BranchRepo { + /** + * Model + * @var App\Models\Branch\Branch + */ + protected $model; + + /** + * New Branch Repo + */ + public function __construct() + { + $this->model = Branch::class; + $this->query = $this->model::query(); + $this->queryActive(); + } + + /** + * Query active records + */ + public function queryActive(): self + { + $this->query->where('active', true); + + return $this; + } + + /** + * "Make" static sugar + */ + public static function make(): self + { + return new self(); + } + + /** + * Query + */ + public function query() + { + return $this->query; + } + /** * Branch values */ public static function values(): Collection|array { - return Branch::pluck('name', 'id'); + return static::make()->pluck('name', 'id'); } }