Skip to content

Commit

Permalink
Required fields (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 authored Sep 9, 2024
1 parent eda24c4 commit 01e91f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/Filament/Resources/OrganisationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,17 @@ public static function form(Form $form): Form
->label(__('organisation.field.risk_category'))
->helperText(__('general.help.multi_select'))
->multiple()
->preload(),
->preload()
->required(),

Select::make('resource_types')
->relationship('resourceTypes', 'name')
->label(__('organisation.field.resource_types'))
->helperText(__('general.help.multi_select'))
->multiple()
->preload()
->columnSpanFull(),
->columnSpanFull()
->required(),
]),

Section::make(__('organisation.section.area_of_activity'))
Expand Down
10 changes: 10 additions & 0 deletions database/factories/OrganisationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public function withRelated(): static
$organisation->riskCategories()
->attach($this->randomRiskCategories(3));

$organisation->resourceTypes()
->attach($this->randomResourceTypes(3));

if ($organisation->has_branches) {
Branch::factory()
->for($organisation)
Expand Down Expand Up @@ -177,4 +180,11 @@ protected function randomRiskCategories(int $count = 1): Collection
->rememberForever('risk_categories', fn () => RiskCategory::pluck('id'))
->random($count);
}

protected function randomResourceTypes(int $count = 1): Collection
{
return Cache::driver('array')
->rememberForever('resource_types', fn () => Organisation\ResourceType::pluck('id'))
->random($count);
}
}

0 comments on commit 01e91f0

Please sign in to comment.