lpj/app/Http/Requests/StatusPermohonanRequest.php

44 lines
1.1 KiB
PHP
Raw Normal View History

2024-08-24 09:05:39 +00:00
<?php
namespace Modules\Lpj\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StatusPermohonanRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules()
: array
{
$rules = [
'description' => 'nullable|max:255',
'status' => 'required|boolean',
];
if ($this->method() == 'PUT') {
$rules['name'] = 'required|max:50|unique:status_permohonan,name,' . $this->id;
} else {
$rules['name'] = 'required|max:50|unique:status_permohonan,name';
}
return $rules;
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize()
: bool
{
return true;
}
public function prepareForValidation()
{
$this->merge([
'status' => isset($this->status) ? 1 : 0,
]);
}
}