forge/app/Traits/ApiResponses.php
Refringe 0e3783555e
Basic API
Includes routes for login, logout, listing users, listing mods, listing a user, and listing a mod. Very basic, just laying out the structure.

https://www.postman.com/refringe/workspace/spt-forge
2024-06-27 16:58:11 -04:00

27 lines
650 B
PHP

<?php
namespace App\Traits;
use Illuminate\Http\JsonResponse;
trait ApiResponses
{
protected function success(string $message, ?array $data = []): JsonResponse
{
return $this->baseResponse(message: $message, data: $data, code: 200);
}
private function baseResponse(?string $message = '', ?array $data = [], ?int $code = 200): JsonResponse
{
return response()->json([
'message' => $message,
'data' => $data,
], $code);
}
protected function error(string $message, int $code): JsonResponse
{
return $this->baseResponse(message: $message, code: $code);
}
}