laravel 8 api in application code example
Example: laravel api response trait
trait RespondsWithHttpStatus
{
protected function success($message, $data = [], $status = 200)
{
return response([
'success' => true,
'data' => $data,
'message' => $message,
], $status);
}
protected function failure($message, $status = 422)
{
return response([
'success' => false,
'message' => $message,
], $status);
}
}