Update Koperasi
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Koperasi;
|
||||
|
||||
use App\Models\Koperasi\PengurusKoperasi;
|
||||
|
||||
abstract class KoperasiTabRequest extends KoperasiRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
$pengurus = $this->route('pengurusKoperasi');
|
||||
|
||||
return $pengurus instanceof PengurusKoperasi && $pengurus->profilLengkap();
|
||||
}
|
||||
|
||||
public function attributes(): array
|
||||
{
|
||||
$attributes = [];
|
||||
foreach (array_keys($this->rules()) as $field) {
|
||||
$attributes[$field] = ucfirst(str_replace(['_', '.*'], [' ', ''], $field));
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
parent::prepareForValidation();
|
||||
|
||||
// Checkbox yang dikosongkan harus menghapus pilihan yang sebelumnya tersimpan.
|
||||
foreach ($this->rules() as $field => $rules) {
|
||||
if (in_array('array', $rules, true) && ! $this->exists($field)) {
|
||||
$this->merge([$field => []]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user