lpj/app/Http/Requests/JenisJaminanRequest.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2024-08-11 07:28:51 +00:00
<?php
2024-08-13 04:54:42 +00:00
namespace Modules\Lpj\Http\Requests;
2024-08-11 07:28:51 +00:00
use daengdeni\LaravelIdGenerator\IdGenerator;
2024-08-13 04:54:42 +00:00
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
2024-08-11 07:28:51 +00:00
2024-08-13 04:54:42 +00:00
class JenisJaminanRequest extends FormRequest
2024-08-11 07:28:51 +00:00
{
2024-08-13 04:54:42 +00:00
/**
* Get the validation rules that apply to the request.
*/
public function rules()
: array
{
return [
'code' => 'required|max:5',
'name' => 'required|max:255',
'slug' => 'required|max:255',
'jenis_legalitas_jaminan_id' => 'nullable',
2024-08-13 04:54:42 +00:00
];
2024-08-11 07:28:51 +00:00
}
2024-08-13 04:54:42 +00:00
/**
* Determine if the user is authorized to make this request.
*/
public function authorize()
: bool
{
return true;
}
public function prepareForValidation()
: void
{
if ($this->method() == 'POST') {
$this->merge([
'code' => IdGenerator::generate(
['table' => 'jenis_jaminan', 'length' => 5, 'prefix' => 'JJ', 'field' => 'code'],
)
]);
}
$this->merge([
'jenis_legalitas_jaminan_id' => json_encode($this->jenis_legalitas_jaminan_id),
'slug' => Str::slug($this->name),
]);
}
2024-08-11 07:28:51 +00:00
}