lpj/app/Http/Requests/JenisLegalitasJaminanRequest.php

49 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2024-08-11 07:22:51 +00:00
<?php
2024-08-13 04:54:42 +00:00
namespace Modules\Lpj\Http\Requests;
2024-08-11 07:22: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:22:51 +00:00
2024-08-13 04:54:42 +00:00
class JenisLegalitasJaminanRequest extends FormRequest
2024-08-11 07:22: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:6',
2024-08-13 04:54:42 +00:00
'name' => 'required|max:255',
'slug' => 'required|max:255',
2024-08-13 04:54:42 +00:00
];
2024-08-11 07:22: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()
{
if($this->method() == 'POST' && $this->code == null) {
$this->merge([
'code' => IdGenerator::generate(
['table' => 'jenis_legalitas_jaminan', 'length' => 6, 'prefix' => 'JLJ', 'field' => 'code'],
),
'slug' => Str::slug($this->name),
]);
} else {
$this->merge([
'slug' => Str::slug($this->name),
]);
}
}
2024-08-11 07:22:51 +00:00
}