49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Lpj\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class KJPPRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'name' => 'required|string|not_regex:/^\d+$/|max:255',
|
|
'jenis_kantor' => 'required'
|
|
];
|
|
|
|
if ($this->method() == 'PUT') {
|
|
$rules['code'] = 'required|max:50|unique:kjpp,code,' . $this->id;
|
|
} else {
|
|
$rules['code'] = 'required|max:50|unique:kjpp,code';
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'code.required' => 'Kode KJPP harus diisi!',
|
|
'code.max' => 'Kode KJPP maksimal 255 huruf!',
|
|
'code.unique' => 'Kode KJPP tidak boleh sama!',
|
|
'name.required' => 'Nama KJPP harus diisi!',
|
|
'name.not_regex' => 'Nama KJPP harus berupa huruf!',
|
|
'name.max' => 'Nama KJPP maksimal 255 huruf!',
|
|
'jenis_kantor.required' => 'Jenis Kantor harus diisi!'
|
|
];
|
|
}
|
|
}
|