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 SubLocationRequest 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'],
|
|
'location_id' => ['required', 'exists:locations,id'],
|
|
'status' => ['required', 'in:0,1'],
|
|
'description' => ['nullable'],
|
|
'enhancer_id' => ['required'],
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'description' => filled($this->description) ? $this->description : null,
|
|
'enhancer_id' => Auth::check() ? Auth::id() : null,
|
|
]);
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => 'Nama sub lokus harus diisi.',
|
|
'name.max' => 'Nama sub lokus tidak boleh lebih dari 100 karakter.',
|
|
'location_id.required' => 'Lokus harus dipilih.',
|
|
'location_id.exists' => 'Lokus 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.',
|
|
];
|
|
}
|
|
}
|