Skip to content

Resources, Requests and Response Shape ​

Overview ​

The Backend-API barely uses Laravel API Resources or Form Requests. Controllers validate inline with Validator::make(...) and return arrays or models through the RestResponse facade, which defines the JSON envelope every client relies on.

FolderClassesReferenced from app/ or routes/
app/Http/Resources9 (Stripe card, invoice and payment shapes)No
app/Http/Requests/LM6 Form Requests for the lead-management (LM) web-form trackerNo
app/RestResource/RestResponse.phpThe response helperYes, about 2,000 calls

Response envelope ​

App\RestResource\RestResponse is bound as RestResponse by RestResourceProvider and aliased in config/app.php. All methods are static and return Response::json(...).

MethodHTTP statusstatuscodemessagedataerror
success($data = [], $msg = 'Success Response')200true200$msg$data[]
error($msg = 'Woops! Something went wrong.', $errorType = null, $data = [])500false500$msg (see below)$datanot set
warning($msg = 'Warning accrued', $code = 402)$codefalse$code$msgnot setnot set
validationError($error = [], $msg = 'Woops! Validation is failed.')400false400$msgnot set$error
sayHello()noneEchoes a test string

Examples:

json
{ "status": true, "code": 200, "message": "Collage list fetched successfully.", "data": { }, "error": [] }
json
{ "status": false, "code": 400, "message": "Woops! Validation is failed.", "error": { "email": ["The email field is required."] } }
json
{ "status": false, "code": 402, "message": "Workspace is not available." }

Things to know when reading or writing controllers:

  • warning() defaults to HTTP 402. Of the 933 RestResponse::warning(...) calls in app/, only 78 pass a numeric status (most often 422, then 420, 400, 404, 403, 201). The rest return 402 for ordinary business errors such as "Workspace is not available." Frontends check status / code in the body, not only the HTTP status.
  • error() hides the message in production. When config('app.env') === 'production' the message becomes Whoops! Something went wrong., the exception message, file and line go to the customlog channel (storage/logs/custom.log), and newrelic_notice_error() runs if the extension is loaded. Outside production the raw exception message is returned. 428 of the 468 calls are RestResponse::error($e->getMessage(), $e) inside a catch.
  • validationError() is normally called as RestResponse::validationError($validate->errors()) (182 calls), so error is the Laravel MessageBag keyed by field.
  • success() always returns 200. RestResponse has no pagination helper; whatever the controller passes (array, model, collection or paginator) is placed in data as is.

Responses that do not use the envelope:

SourceShape
Authenticate::unauthenticated() (all auth:* guards){"error": "Unauthenticated."}, 401
CheckExternalUser middleware{"error": "Unauthenticated."} 401, or {"error": "Your account is inactive."} 403
SsoEntryCheck via VerifyUserWithWorkSpaceEnvelope keys plus data.sso_recheck (required with redirect_url, 428; or failed, 403)
HealthController@index (GET /health){status: ok/degraded, app, environment, timestamp, checks}, 200 or 503
SSO redirect / acs, social login callbackHTTP redirects to {origin}/social-login?... (see Services)
Back-office controllers (Web/AdminController, Web/AdminUsersController, Web/OperationsController)Their own response()->json(...) arrays

App\Exceptions\Handler has no render() override (an old envelope-style render is commented out), so uncaught exceptions use Laravel's default JSON error format. OAuthServerException is in $dontReport.

API Resources (app/Http/Resources) ​

None of these classes is used by a controller. Stripe data in the subscription controllers is returned directly. They are listed so nobody assumes they define the live response.

ClassBasetoArray output
CardResourceJsonResourceid, brand, country, customer, cvc_check, dynamic_last4, exp_month, exp_year, fingerprint, funding, last4, name
InvoiceResourceJsonResourceid, number, payment_id (payment_intent), subscription_id (subscription), name (customer_name), email (customer_email), amount (total), status, currency, invoice_pdf, start_date and end_date (first line item period, Y-m-d), plan_name (first line item plan.product)
PaymentResourceJsonResourceCard: id, type = card, brand, country, exp_month, exp_year, funding, last4. US bank account: id, type = us_bank_transfer, account_holder_type, account_type, bank_name, last4. Anything else: []
Card, CardCollection, Invoice, InvoiceCollection, Payment, PaymentCollectionResourceCollectionparent::toArray($request) (no custom fields)

Form Requests (app/Http/Requests/LM) ​

All six return true from authorize() and override failedValidation() to throw an HttpResponseException with the same envelope as validationError(): {status: false, code: 400, message, error: $errors->messages()}, HTTP 400. None is type-hinted in any controller in this snapshot.

FindFormRequest ​

FieldRules
workspace_idrequired, exists:workspaces,url_slug
urlarray
url.0required
url.*url, active_url, closure: every URL must share the primary domain of url.0

When the domain closure fails, message becomes Multiple primary domains detected. Please include URLs that share the same primary domain.

FormStoreRequest ​

FieldRules
workspace_idrequired, exists:workspaces,url_slug
formsrequired, array
forms.*.name, forms.*.attr_id, forms.*.attr_name, forms.*.attr_class, forms.*.attr_method, forms.*.attr_actionnullable, string
forms.*.page_urlrequired, string
forms.*.fieldInforequired, array, unique_attribute_values:request_name,custom_field,custom_field_name
forms.*.fieldInfo.*.attr_id, attr_name, attr_class, attr_type, input, label, custom_field_namenullable, string
forms.*.fieldInfo.*.attr_multiplenullable
forms.*.fieldInfo.*.request_namerequired, string

unique_attribute_values is a custom rule registered in AppServiceProvider::boot(). For each fieldInfo item it takes request_name; when that equals custom_field it uses custom_field_name instead. A repeated value adds the error {param} '{value}' must be unique, found multiple times on {attribute}.{index}.request_name. The rule itself always returns true.

FormUpdateRequest ​

FieldRules
workspace_idrequired, exists:workspaces,url_slug
namerequired, string

LeadStatusUpdateRequest ​

FieldRules
workspace_idrequired, exists:workspaces,url_slug
status_idrequired, in: keys of App\Models\LM\Lead::STATUS_LIST (1 Open, 2 Qualified, 3 Unqualified, 4 Closed, 5 Contacted, 6 Pending, 7 Hold, 8 Rejected)

VerifyScriptsRequest ​

FieldRules
workspace_idrequired, exists:workspaces,url_slug
form_idsnullable, array

VerifyUrlRequest ​

FieldRules
urlrequired, url, active_url

messages() also defines workspace_id.exists, but there is no workspace_id rule.

Inline validation pattern ​

Because Form Requests are not used, a typical controller method looks like this:

php
$validate = Validator::make($request->all(), [
    // field rules
]);
if ($validate->fails()) {
    return RestResponse::validationError($validate->errors());
}
try {
    // ...
    return RestResponse::success($data, 'Message.');
} catch (\Exception $e) {
    return RestResponse::error($e->getMessage(), $e);
}

Business-rule failures inside the try return RestResponse::warning('...') (HTTP 402 unless a code is passed).