- Laravel 11.51 + PHP 8.4 in backend/
- MySQL 9 connection (DBngin, db: verde)
- Installed Sanctum, Spatie permission/activitylog/model-states,
matanyadaev/laravel-eloquent-spatial
- API routes prefixed /api/v1 in bootstrap/app.php
- Standard response envelope { success, data, message, errors, meta }
via ApiResponse + ApiController base class
- Global exception handlers for validation/auth/not-found/http errors
on api/* routes (always JSON, never redirect to login)
- Extended users migration: uuid, phone+verified_at, role enum
(admin/resident/driver/helper/scanner/store_partner), status,
first/middle/last name, avatar_path, preferred_language, fcm_token,
last_login_at, soft deletes
- User model: HasApiTokens, HasRoles, LogsActivity, SoftDeletes,
role/status constants, auto-uuid on create
- Health endpoint at GET /api/v1/health verifies DB connection
- backend/CLAUDE.md documenting backend conventions
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Responses;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class ApiResponse
|
|
{
|
|
/**
|
|
* Standard success envelope: { success, data, message, errors, meta }.
|
|
*/
|
|
public static function success(
|
|
mixed $data = null,
|
|
?string $message = null,
|
|
array $meta = [],
|
|
int $status = Response::HTTP_OK,
|
|
): JsonResponse {
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $data,
|
|
'message' => $message,
|
|
'errors' => null,
|
|
'meta' => (object) $meta,
|
|
], $status);
|
|
}
|
|
|
|
/**
|
|
* Standard error envelope. Use HTTP_UNPROCESSABLE_ENTITY for validation,
|
|
* HTTP_NOT_FOUND for missing resources, etc.
|
|
*/
|
|
public static function error(
|
|
string $message,
|
|
mixed $errors = null,
|
|
int $status = Response::HTTP_BAD_REQUEST,
|
|
array $meta = [],
|
|
): JsonResponse {
|
|
return response()->json([
|
|
'success' => false,
|
|
'data' => null,
|
|
'message' => $message,
|
|
'errors' => $errors,
|
|
'meta' => (object) $meta,
|
|
], $status);
|
|
}
|
|
}
|