Update Module Debitur
penambahan default cif 0x10 dan di buat mandatory update field npwp input harus minimal 15 dan maksimal 16 digit penambahan rules
This commit is contained in:
parent
5619c52b0a
commit
9ecdaa0cdd
@ -71,6 +71,7 @@
|
||||
|
||||
public function update(DebitureRequest $request, $id)
|
||||
{
|
||||
//print_r($request->all());exit;
|
||||
$validate = $request->validated();
|
||||
|
||||
if ($validate) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Modules\Lpj\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Modules\Lpj\Rules\UniqueCifExceptZero;
|
||||
|
||||
class DebitureRequest extends FormRequest
|
||||
{
|
||||
@ -21,7 +22,7 @@
|
||||
'nomor_rekening' => 'nullable|string|max:50',
|
||||
'name' => 'required',
|
||||
'registered_at' => 'nullable|date',
|
||||
'npwp' => 'nullable|string|max:16',
|
||||
'npwp' => 'nullable|string|min:15|max:16',
|
||||
'email' => 'nullable|email',
|
||||
'phone' => 'nullable|string|max:15',
|
||||
'address' => 'nullable|string',
|
||||
@ -29,10 +30,10 @@
|
||||
'status' => 'nullable|boolean'
|
||||
];
|
||||
|
||||
if ($this->method() == 'PUT') {
|
||||
$rules['cif'] = 'nullable|unique:debitures,cif,' . $this->id;
|
||||
} else {
|
||||
$rules['cif'] = 'nullable|unique:debitures,cif';
|
||||
if($this->method() == 'PUT'){
|
||||
$rules['cif'] = ['required', new UniqueCifExceptZero($this->id)];
|
||||
}else{
|
||||
$rules['cif'] = ['required', new UniqueCifExceptZero(null)];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
|
25
app/Rules/UniqueCifExceptZero.php
Normal file
25
app/Rules/UniqueCifExceptZero.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
|
||||
class UniqueCifExceptZero implements ValidationRule
|
||||
{
|
||||
public function __construct($id = null)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function validate($attribute, $value, $fail): void
|
||||
{
|
||||
if (Debiture::where($attribute, $value)
|
||||
->where('id', '!=', $this->id)
|
||||
->where($attribute, '!=', '000000')
|
||||
->exists()) {
|
||||
$fail('The :attribute field must be uniquse.'.$this->id);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<form action="{{ isset($debitur->id) ? route('debitur.update', $debitur->id) : route('debitur.store') }}" method="POST" class="grid gap-5">
|
||||
@if(isset($debitur->id))
|
||||
<input type="hidden" name="id" value="{{ $debitur->id }}">
|
||||
@method('PUT')
|
||||
@endif
|
||||
@csrf
|
||||
@ -29,7 +30,7 @@
|
||||
CIF
|
||||
</label>
|
||||
<div class="flex flex-wrap items-baseline w-full">
|
||||
<input class="input @error('cif') border-danger bg-danger-light @enderror" type="number" name="cif" value="{{ $debitur->cif ?? '' }}">
|
||||
<input class="input @error('cif') border-danger bg-danger-light @enderror" type="number" name="cif" value="{{ $debitur->cif ?? '0000000000' }}">
|
||||
@error('cif')
|
||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||
@enderror
|
||||
|
Loading…
Reference in New Issue
Block a user