This commit is contained in:
2023-11-28 12:40:49 +05:00
parent b45cec0200
commit dab7cc0069
16 changed files with 215 additions and 58 deletions

View File

@@ -3,7 +3,7 @@
namespace App\Nova\Resources\Branch;
use App\Models\Branch\Branch as BranchModel;
use App\Nova\Resources\Branch\Concerns\BranchNovaRepo;
use App\Repos\System\Nova\NovaRepo;
use App\Repos\System\Settings\Location\RegionRepo;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
@@ -78,7 +78,7 @@ class Branch extends Resource
Select::make(__('Province'), 'province_id')
->displayUsingLabels()
->searchable()
->dependsOn('region', BranchNovaRepo::dependsOnRegion()),
->dependsOn('region', NovaRepo::dependsOnRegion('region')),
Text::make(__('Unique code'), 'unique_code')
->rules('required', 'string', 'max:255'),

View File

@@ -1,23 +0,0 @@
<?php
namespace App\Nova\Resources\Branch\Concerns;
use App\Models\System\Location\Province;
use Closure;
class BranchNovaRepo
{
/**
* Depends on region
*/
public static function dependsOnRegion(string $attribute = 'region'): Closure
{
return function ($field, $request, $formData) use ($attribute) {
$field->options(
$formData->{$attribute}
? Province::where('region', $formData->{$attribute})->pluck('name', 'id')
: []
);
};
}
}