big update base struktur tahap 1
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\MenuGroup;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateMenuGroupRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$menuGroupId = $this->route('menu_group')?->id;
|
||||
$isMaster = $this->user()?->isMasterAdmin() ?? false;
|
||||
$tenantId = $isMaster
|
||||
? ($this->exists('tenant_id')
|
||||
? $this->input('tenant_id')
|
||||
: $this->route('menu_group')?->tenant_id)
|
||||
: $this->route('menu_group')?->tenant_id;
|
||||
|
||||
return [
|
||||
'tenant_id' => [
|
||||
$isMaster ? 'nullable' : 'prohibited',
|
||||
'integer',
|
||||
'exists:tenants,id',
|
||||
],
|
||||
'name' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:100',
|
||||
Rule::unique('menu_groups', 'name')
|
||||
->where(fn ($query) => $tenantId
|
||||
? $query->where('tenant_id', $tenantId)
|
||||
: $query->whereNull('tenant_id'))
|
||||
->ignore($menuGroupId),
|
||||
],
|
||||
'description' => [
|
||||
'nullable',
|
||||
'string',
|
||||
],
|
||||
'is_active' => [
|
||||
'nullable',
|
||||
'boolean',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'is_active' => filter_var(
|
||||
$this->is_active,
|
||||
FILTER_VALIDATE_BOOLEAN,
|
||||
FILTER_NULL_ON_FAILURE
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user