You can also create response macros in boot method of your AppServiceProvider
Response::macro('success', function (string $message, array $data = [], int $status =200) {
return response()->json([
'message' => $message,
'status' => true,
'data' => $data,
], $status);
});
Response::macro('error', function (string $message, array $errors = [], int $status = 400) {
return response()->json([
'errors' => $errors,
'status' => false,
'message' => $message,
], $status);
});