Manage clients, testimonials and talks through the API
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
47
app/Http/Requests/Api/V1/ClientRequest.php
Normal file
47
app/Http/Requests/Api/V1/ClientRequest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Api\V1;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Rules\Translatable;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
/**
|
||||
* The panel's client form, as rules.
|
||||
*/
|
||||
class ClientRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$client = $this->route('client');
|
||||
$creating = ! $client instanceof Client;
|
||||
$sometimes = $creating ? 'required' : 'sometimes';
|
||||
|
||||
return [
|
||||
'name' => [$sometimes, 'string', 'max:255'],
|
||||
'slug' => [
|
||||
$sometimes,
|
||||
'string',
|
||||
'max:255',
|
||||
'alpha_dash:ascii',
|
||||
Rule::unique('clients', 'slug')->ignore($client?->id),
|
||||
],
|
||||
'sector' => ['sometimes', 'nullable', new Translatable(max: 120)],
|
||||
'logo' => ['sometimes', 'nullable', 'string', 'max:2048'],
|
||||
'url' => ['sometimes', 'nullable', 'url', 'max:2048'],
|
||||
'is_public' => ['sometimes', 'boolean'],
|
||||
'position' => ['sometimes', 'integer', 'min:0'],
|
||||
];
|
||||
}
|
||||
}
|
||||
45
app/Http/Requests/Api/V1/TalkRequest.php
Normal file
45
app/Http/Requests/Api/V1/TalkRequest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Api\V1;
|
||||
|
||||
use App\Models\Talk;
|
||||
use App\Rules\Translatable;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
/**
|
||||
* The panel's talk form, as rules. The title is the one the talk was given
|
||||
* under, in `language`; only the summary is translated.
|
||||
*/
|
||||
class TalkRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$creating = ! $this->route('talk') instanceof Talk;
|
||||
$sometimes = $creating ? 'required' : 'sometimes';
|
||||
|
||||
return [
|
||||
'title' => [$sometimes, 'string', 'max:255'],
|
||||
'language' => [$sometimes, 'string', Rule::in(array_keys((array) config('locales.supported')))],
|
||||
'summary' => ['sometimes', 'nullable', new Translatable(max: 500)],
|
||||
'event' => [$sometimes, 'string', 'max:255'],
|
||||
'city' => ['sometimes', 'nullable', 'string', 'max:120'],
|
||||
'held_at' => ['sometimes', 'nullable', 'date'],
|
||||
'video_url' => ['sometimes', 'nullable', 'url', 'max:2048'],
|
||||
'slides_url' => ['sometimes', 'nullable', 'url', 'max:2048'],
|
||||
'member_id' => ['sometimes', 'nullable', 'integer', Rule::exists('members', 'id')->whereNull('deleted_at')],
|
||||
'project_id' => ['sometimes', 'nullable', 'integer', Rule::exists('projects', 'id')->whereNull('deleted_at')],
|
||||
'is_public' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
47
app/Http/Requests/Api/V1/TestimonialRequest.php
Normal file
47
app/Http/Requests/Api/V1/TestimonialRequest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Api\V1;
|
||||
|
||||
use App\Models\Testimonial;
|
||||
use App\Rules\Translatable;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
/**
|
||||
* The panel's testimonial form, as rules.
|
||||
*
|
||||
* `original_locale` says which language the person actually spoke in; the
|
||||
* other entries of `quote` are translations of it.
|
||||
*/
|
||||
class TestimonialRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$creating = ! $this->route('testimonial') instanceof Testimonial;
|
||||
$sometimes = $creating ? 'required' : 'sometimes';
|
||||
|
||||
return [
|
||||
'quote' => [$sometimes, new Translatable(max: 1000)],
|
||||
'original_locale' => [$sometimes, 'string', Rule::in(array_keys((array) config('locales.supported')))],
|
||||
'author_name' => [$sometimes, 'string', 'max:255'],
|
||||
'author_role' => ['sometimes', 'nullable', new Translatable(max: 255)],
|
||||
'avatar' => ['sometimes', 'nullable', 'string', 'max:2048'],
|
||||
'client_id' => ['sometimes', 'nullable', 'integer', Rule::exists('clients', 'id')->whereNull('deleted_at')],
|
||||
'project_id' => ['sometimes', 'nullable', 'integer', Rule::exists('projects', 'id')->whereNull('deleted_at')],
|
||||
'service_id' => ['sometimes', 'nullable', 'integer', Rule::exists('services', 'id')->whereNull('deleted_at')],
|
||||
'is_public' => ['sometimes', 'boolean'],
|
||||
'position' => ['sometimes', 'integer', 'min:0'],
|
||||
'given_at' => ['sometimes', 'nullable', 'date'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user