46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?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'],
|
|
];
|
|
}
|
|
}
|