- 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.
30 lines
836 B
PHP
30 lines
836 B
PHP
<?php
|
|
|
|
namespace App\Domains\Auth\Controllers;
|
|
|
|
use App\Domains\Auth\Requests\RegisterUserRequest;
|
|
use App\Domains\Auth\Resources\UserResource;
|
|
use App\Domains\Auth\Services\RegisterUserService;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class RegisterController extends Controller
|
|
{
|
|
public function __construct(
|
|
protected RegisterUserService $registerUserService,
|
|
) {}
|
|
|
|
public function __invoke(RegisterUserRequest $request): JsonResponse
|
|
{
|
|
$user = $this->registerUserService->register($request->validated());
|
|
|
|
return UserResource::make($user)
|
|
->additional([
|
|
'code' => 'auth.register_success',
|
|
'message' => __('api.auth.register_success'),
|
|
])
|
|
->response()
|
|
->setStatusCode(201);
|
|
}
|
|
}
|