42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Integration\Requests;
|
|
|
|
use App\Domains\Integration\Models\Integration;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class ConfigureIntegrationRequest extends FormRequest
|
|
{
|
|
protected ?Integration $integrationModel = null;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user()?->can('manage', Integration::class) ?? false;
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->integrationModel = Integration::query()
|
|
->where('integration_code', $this->route('integration_code'))
|
|
->first();
|
|
|
|
if (! $this->integrationModel) {
|
|
throw ValidationException::withMessages([
|
|
'integration_code' => __('api.integration.not_configured'),
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$rules = ['integration_data' => ['present', 'array']];
|
|
|
|
foreach ($this->integrationModel?->integration_data_schema ?? [] as $field => $rule) {
|
|
$rules['integration_data.'.$field] = $rule;
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
}
|