Expand support API validation for writable resources
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Support\Resources;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SupportTaskResourceRequest extends SupportResourceFormRequest
|
||||
{
|
||||
public static function rulesFor(string $action, ?Model $model = null): array
|
||||
{
|
||||
$rules = [
|
||||
'emotion_id' => ['sometimes', 'integer', 'exists:emotions,id'],
|
||||
'event_type_id' => ['sometimes', 'nullable', 'integer', 'exists:event_types,id'],
|
||||
'title' => ['sometimes', 'array'],
|
||||
'title.de' => ['required_with:title', 'string', 'max:255'],
|
||||
'title.en' => ['required_with:title', 'string', 'max:255'],
|
||||
'description' => ['sometimes', 'array'],
|
||||
'description.de' => ['nullable', 'string'],
|
||||
'description.en' => ['nullable', 'string'],
|
||||
'example_text' => ['sometimes', 'array'],
|
||||
'example_text.de' => ['nullable', 'string'],
|
||||
'example_text.en' => ['nullable', 'string'],
|
||||
'difficulty' => ['sometimes', 'string', Rule::in(['easy', 'medium', 'hard'])],
|
||||
'sort_order' => ['sometimes', 'integer', 'min:0'],
|
||||
'is_active' => ['sometimes', 'boolean'],
|
||||
];
|
||||
|
||||
if ($action === 'create') {
|
||||
$rules['emotion_id'] = ['required', 'integer', 'exists:emotions,id'];
|
||||
$rules['title'] = ['required', 'array'];
|
||||
$rules['title.de'] = ['required', 'string', 'max:255'];
|
||||
$rules['title.en'] = ['required', 'string', 'max:255'];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public static function allowedFields(string $action): array
|
||||
{
|
||||
return [
|
||||
'emotion_id',
|
||||
'event_type_id',
|
||||
'title',
|
||||
'description',
|
||||
'example_text',
|
||||
'difficulty',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user