- 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.
50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Menu\Requests;
|
|
|
|
use App\Domains\Menu\Models\Menu;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class StoreTenantMenuRequest extends FormRequest
|
|
{
|
|
private ?Menu $menuModel = null;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->menuModel = Menu::query()
|
|
->where('code', $this->route('menu_code'))
|
|
->first();
|
|
|
|
if (! $this->menuModel) {
|
|
throw ValidationException::withMessages([
|
|
'menu_code' => __('api.menu.not_found'),
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
if ($this->menuModel?->content_type !== Menu::CONTENT_TYPE_STATIC) {
|
|
return [
|
|
'static_content' => ['nullable', 'array'],
|
|
];
|
|
}
|
|
|
|
$rules = [
|
|
'static_content' => ['required', 'array'],
|
|
];
|
|
|
|
foreach ($this->menuModel->static_content_schema as $field => $rule) {
|
|
$rules["static_content.{$field}"] = $rule;
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
}
|