55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class SubClassificationRequest 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'],
|
|
'classification_id' => ['required', 'exists:classifications,id'],
|
|
'status' => ['required', 'in:0,1'],
|
|
'description' => ['nullable']
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'description' => filled($this->description) ? $this->description : null,
|
|
]);
|
|
}
|
|
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => 'Nama sub klasifikasi harus diisi.',
|
|
'name.max' => 'Nama sub klasifikasi tidak boleh lebih dari 100 karakter.',
|
|
'classification_id.required' => 'Klasifikasi harus dipilih.',
|
|
'classification_id.exists' => 'Klasifikasi yang dipilih tidak valid.',
|
|
'status.required' => 'Status harus dipilih.',
|
|
'status.in' => 'Status harus bernilai aktif atau tidak aktif.',
|
|
'description.nullable' => 'Deskripsi boleh kosong jika tidak diperlukan.',
|
|
];
|
|
}
|
|
|
|
}
|