Files
lpj/app/Http/Requests/JenisLegalitasJaminanRequest.php
Daeng Deni Mardaeni ec6cb8e09f Add custom fields to JenisLegalitasJaminan
Added `custom_field` and `custom_field_type` columns to the `jenis_legalitas_jaminan` table. Updated model, migration, and request files to handle these new fields, ensuring they are optional and have a maximum length of 255 characters.
2024-11-04 16:00:10 +07:00

51 lines
1.5 KiB
PHP

<?php
namespace Modules\Lpj\Http\Requests;
use daengdeni\LaravelIdGenerator\IdGenerator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
class JenisLegalitasJaminanRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules()
: array
{
return [
'code' => 'required|max:6',
'name' => 'required|max:255',
'slug' => 'required|max:255',
'custom_field' => 'nullable|max:255',
'custom_field_type' => 'nullable|max:255',
];
}
/**
* 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),
]);
}
}
}