- Added localization support for API responses in English and Spanish. - Introduced a middleware to set the API locale based on the Accept-Language header. - Updated various exception messages and validation responses to use localized strings. - Created new language files for English and Spanish translations. - Refactored existing code to replace hardcoded messages with localized strings. - Added tests to verify localization functionality and response correctness.
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Integration\Requests;
|
|
|
|
use App\Domains\Integration\Models\Integration;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class StoreTenantIntegrationRequest extends FormRequest
|
|
{
|
|
protected ?Integration $integrationModel = null;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected function prepareForValidation()
|
|
{
|
|
$integrationCode = $this->route('integration_code');
|
|
$this->integrationModel = Integration::where('integration_code', $integrationCode)->first();
|
|
|
|
if (! $this->integrationModel) {
|
|
throw ValidationException::withMessages([
|
|
'integration_code' => __('api.integration.not_configured'),
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$rules = [];
|
|
|
|
// Dynamic validation rules based on the integration data schema
|
|
if ($this->integrationModel && $this->integrationModel->integration_data_schema) {
|
|
foreach ($this->integrationModel->integration_data_schema as $field => $rule) {
|
|
$rules['integration_data.'.$field] = $rule;
|
|
}
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
}
|