38 lines
1000 B
PHP
38 lines
1000 B
PHP
<?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 => []]);
|
|
}
|
|
}
|
|
}
|
|
}
|