simedkom/app/Http/Requests/AiringProofThemeRequest.php
2025-10-13 08:35:36 +07:00

53 lines
1.5 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
class AiringProofThemeRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return Auth::check() && is_role(['1']);
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => ['required', 'max:100'],
'year' => ['required', 'max:5'],
'description' => ['nullable'],
'slug' => ['required'],
'enhancer_id' => ['required'],
];
}
public function messages(): array
{
return [
'name.required' => 'Nama harus diisi.',
'name.max' => 'Nama tidak boleh lebih dari 100 karakter.',
'year.required' => 'Tahun harus diisi.',
'year.max' => 'Tahun tidak boleh lebih dari 5 karakter.',
'description.nullable' => 'Deskripsi bersifat opsional.',
];
}
protected function prepareForValidation()
{
$this->merge([
'slug' => filled($this->name) && filled($this->year) ? \Illuminate\Support\Str::slug($this->name.' '.$this->year) : null,
'enhancer_id' => Auth::check() ? Auth::id() : null,
]);
}
}