refactor(meta): own the platforms.*.meta parent rule in PostPlatformMetaRules
The shared rules() returned only meta sub-keys, so every caller still repeated its own 'platforms.*.meta' => array parent (with slightly different sometimes/ nullable combos). Fold the parent into rules() with a single safe contract so callers just spread one source for the whole meta block.
This commit is contained in:
parent
3aa4b2a2f0
commit
ba20534a6d
6 changed files with 4 additions and 7 deletions
|
|
@ -50,7 +50,6 @@ public function rules(): array
|
|||
Rule::in(array_column(ContentType::cases(), 'value')),
|
||||
new ContentTypeMatchesPlatform,
|
||||
],
|
||||
'platforms.*.meta' => ['sometimes', 'nullable', 'array'],
|
||||
...PostPlatformMetaRules::rules(),
|
||||
'scheduled_at' => ['nullable', 'date', 'after:now'],
|
||||
'label_ids' => ['sometimes', 'array'],
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ public function rules(): array
|
|||
Rule::in(array_column(ContentType::cases(), 'value')),
|
||||
new ContentTypeMatchesPostPlatform,
|
||||
],
|
||||
'platforms.*.meta' => ['nullable', 'array'],
|
||||
...PostPlatformMetaRules::rules(),
|
||||
'scheduled_at' => [
|
||||
'nullable',
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ public function rules(): array
|
|||
Rule::in(array_column(ContentType::cases(), 'value')),
|
||||
Rule::when($enforcesMediaCompatibility, [new ContentTypeCompatibleWithMedia]),
|
||||
],
|
||||
'platforms.*.meta' => ['nullable', 'array'],
|
||||
...PostPlatformMetaRules::rules(),
|
||||
'label_ids' => ['sometimes', 'array'],
|
||||
'label_ids.*' => ['uuid', Rule::exists('workspace_labels', 'id')->where('workspace_id', $this->user()->currentWorkspace->id)],
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ public function handle(Request $request): ResponseFactory
|
|||
->where('is_active', true),
|
||||
],
|
||||
'platforms.*.content_type' => ['required', 'string', Rule::in(array_column(ContentType::cases(), 'value')), new ContentTypeMatchesPlatform],
|
||||
'platforms.*.meta' => ['sometimes', 'array'],
|
||||
...PostPlatformMetaRules::rules(),
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ public function handle(Request $request): Response|ResponseFactory
|
|||
Rule::exists('post_platforms', 'id')->where('post_id', $post->id),
|
||||
],
|
||||
'platforms.*.content_type' => ['sometimes', 'string', Rule::in(array_column(ContentType::cases(), 'value')), new ContentTypeMatchesPostPlatform],
|
||||
'platforms.*.meta' => ['sometimes', 'array'],
|
||||
...PostPlatformMetaRules::rules(),
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,14 +32,16 @@ class PostPlatformMetaRules
|
|||
];
|
||||
|
||||
/**
|
||||
* Validation rules for the `platforms.*.meta.*` keys. The caller keeps its own
|
||||
* `platforms.*.meta` (array) parent rule; these are the per-platform sub-keys.
|
||||
* Validation rules for `platforms.*.meta` and all its per-platform sub-keys.
|
||||
* Spread into a FormRequest/MCP tool rule set as the complete meta contract.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function rules(): array
|
||||
{
|
||||
return [
|
||||
'platforms.*.meta' => ['sometimes', 'nullable', 'array'],
|
||||
|
||||
// Instagram / Facebook
|
||||
'platforms.*.meta.aspect_ratio' => ['sometimes', 'nullable', 'string', Rule::enum(AspectRatio::class)],
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue