Expand support API validation for writable resources
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Support\Resources;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SupportBlogPostResourceRequest extends SupportResourceFormRequest
|
||||
{
|
||||
public static function rulesFor(string $action, ?Model $model = null): array
|
||||
{
|
||||
$postId = $model?->getKey();
|
||||
|
||||
$rules = [
|
||||
'blog_category_id' => ['sometimes', 'integer', 'exists:blog_categories,id'],
|
||||
'slug' => [
|
||||
'sometimes',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('blog_posts', 'slug')->ignore($postId),
|
||||
],
|
||||
'banner' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'published_at' => ['sometimes', 'nullable', 'date'],
|
||||
'is_published' => ['sometimes', 'boolean'],
|
||||
'title' => ['sometimes', 'array'],
|
||||
'title.de' => ['required_with:title', 'string', 'max:255'],
|
||||
'title.en' => ['nullable', 'string', 'max:255'],
|
||||
'content' => ['sometimes', 'array'],
|
||||
'content.de' => ['required_with:content', 'string'],
|
||||
'content.en' => ['nullable', 'string'],
|
||||
'excerpt' => ['sometimes', 'array'],
|
||||
'excerpt.de' => ['nullable', 'string'],
|
||||
'excerpt.en' => ['nullable', 'string'],
|
||||
'meta_title' => ['sometimes', 'array'],
|
||||
'meta_title.de' => ['nullable', 'string', 'max:255'],
|
||||
'meta_title.en' => ['nullable', 'string', 'max:255'],
|
||||
'meta_description' => ['sometimes', 'array'],
|
||||
'meta_description.de' => ['nullable', 'string'],
|
||||
'meta_description.en' => ['nullable', 'string'],
|
||||
'translations' => ['sometimes', 'array'],
|
||||
];
|
||||
|
||||
if ($action === 'create') {
|
||||
$rules['blog_category_id'] = ['required', 'integer', 'exists:blog_categories,id'];
|
||||
$rules['slug'] = ['required', 'string', 'max:255', Rule::unique('blog_posts', 'slug')];
|
||||
$rules['title'] = ['required', 'array'];
|
||||
$rules['title.de'] = ['required', 'string', 'max:255'];
|
||||
$rules['content'] = ['required', 'array'];
|
||||
$rules['content.de'] = ['required', 'string'];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public static function allowedFields(string $action): array
|
||||
{
|
||||
return [
|
||||
'blog_category_id',
|
||||
'slug',
|
||||
'banner',
|
||||
'published_at',
|
||||
'is_published',
|
||||
'title',
|
||||
'content',
|
||||
'excerpt',
|
||||
'meta_title',
|
||||
'meta_description',
|
||||
'translations',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Support\Resources;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SupportEmotionResourceRequest extends SupportResourceFormRequest
|
||||
{
|
||||
public static function rulesFor(string $action, ?Model $model = null): array
|
||||
{
|
||||
$rules = [
|
||||
'name' => ['sometimes', 'array'],
|
||||
'name.de' => ['required_with:name', 'string', 'max:255'],
|
||||
'name.en' => ['required_with:name', 'string', 'max:255'],
|
||||
'description' => ['sometimes', 'array'],
|
||||
'description.de' => ['nullable', 'string'],
|
||||
'description.en' => ['nullable', 'string'],
|
||||
'icon' => ['sometimes', 'nullable', 'string', 'max:50'],
|
||||
'color' => ['sometimes', 'nullable', 'string', 'max:7'],
|
||||
'sort_order' => ['sometimes', 'integer', 'min:0'],
|
||||
'is_active' => ['sometimes', 'boolean'],
|
||||
'tenant_id' => ['sometimes', 'nullable', 'integer', 'exists:tenants,id'],
|
||||
];
|
||||
|
||||
if ($action === 'create') {
|
||||
$rules['name'] = ['required', 'array'];
|
||||
$rules['name.de'] = ['required', 'string', 'max:255'];
|
||||
$rules['name.en'] = ['required', 'string', 'max:255'];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public static function allowedFields(string $action): array
|
||||
{
|
||||
return [
|
||||
'name',
|
||||
'description',
|
||||
'icon',
|
||||
'color',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
'tenant_id',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Support\Resources;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SupportEventResourceRequest extends SupportResourceFormRequest
|
||||
{
|
||||
public static function rulesFor(string $action, ?Model $model = null): array
|
||||
{
|
||||
$eventId = $model?->getKey();
|
||||
|
||||
$rules = [
|
||||
'name' => ['sometimes', 'array'],
|
||||
'name.de' => ['required_with:name', 'string', 'max:255'],
|
||||
'name.en' => ['nullable', 'string', 'max:255'],
|
||||
'description' => ['sometimes', 'array'],
|
||||
'description.de' => ['nullable', 'string'],
|
||||
'description.en' => ['nullable', 'string'],
|
||||
'slug' => [
|
||||
'sometimes',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('events', 'slug')->ignore($eventId),
|
||||
],
|
||||
'date' => ['sometimes', 'date'],
|
||||
'location' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'max_participants' => ['sometimes', 'nullable', 'integer', 'min:0'],
|
||||
'event_type_id' => ['sometimes', 'nullable', 'integer', 'exists:event_types,id'],
|
||||
'default_locale' => ['sometimes', 'string', 'max:5'],
|
||||
'is_active' => ['sometimes', 'boolean'],
|
||||
'status' => ['sometimes', 'string', Rule::in(['draft', 'published', 'archived'])],
|
||||
'settings' => ['sometimes', 'array'],
|
||||
'join_link_enabled' => ['sometimes', 'boolean'],
|
||||
'photo_upload_enabled' => ['sometimes', 'boolean'],
|
||||
'task_checklist_enabled' => ['sometimes', 'boolean'],
|
||||
];
|
||||
|
||||
if ($action === 'create') {
|
||||
$rules['name'] = ['required', 'array'];
|
||||
$rules['name.de'] = ['required', 'string', 'max:255'];
|
||||
$rules['slug'] = [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('events', 'slug'),
|
||||
];
|
||||
$rules['date'] = ['required', 'date'];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public static function allowedFields(string $action): array
|
||||
{
|
||||
return [
|
||||
'name',
|
||||
'description',
|
||||
'slug',
|
||||
'date',
|
||||
'location',
|
||||
'max_participants',
|
||||
'event_type_id',
|
||||
'default_locale',
|
||||
'is_active',
|
||||
'status',
|
||||
'settings',
|
||||
'join_link_enabled',
|
||||
'photo_upload_enabled',
|
||||
'task_checklist_enabled',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Support\Resources;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SupportPhotoResourceRequest extends SupportResourceFormRequest
|
||||
{
|
||||
public static function rulesFor(string $action, ?Model $model = null): array
|
||||
{
|
||||
return [
|
||||
'status' => ['sometimes', 'string', Rule::in(['pending', 'approved', 'rejected', 'hidden'])],
|
||||
'moderation_notes' => ['nullable', 'required_if:status,rejected', 'string', 'max:1000'],
|
||||
'is_featured' => ['sometimes', 'boolean'],
|
||||
'emotion_id' => ['sometimes', 'nullable', 'integer', 'exists:emotions,id'],
|
||||
'task_id' => ['sometimes', 'nullable', 'integer', 'exists:tasks,id'],
|
||||
];
|
||||
}
|
||||
|
||||
public static function allowedFields(string $action): array
|
||||
{
|
||||
return [
|
||||
'status',
|
||||
'moderation_notes',
|
||||
'is_featured',
|
||||
'emotion_id',
|
||||
'task_id',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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