Appearance
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.
| Folder | Classes | Referenced from app/ or routes/ |
|---|---|---|
app/Http/Resources | 9 (Stripe card, invoice and payment shapes) | No |
app/Http/Requests/LM | 6 Form Requests for the lead-management (LM) web-form tracker | No |
app/RestResource/RestResponse.php | The response helper | Yes, 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(...).
| Method | HTTP status | status | code | message | data | error |
|---|---|---|---|---|---|---|
success($data = [], $msg = 'Success Response') | 200 | true | 200 | $msg | $data | [] |
error($msg = 'Woops! Something went wrong.', $errorType = null, $data = []) | 500 | false | 500 | $msg (see below) | $data | not set |
warning($msg = 'Warning accrued', $code = 402) | $code | false | $code | $msg | not set | not set |
validationError($error = [], $msg = 'Woops! Validation is failed.') | 400 | false | 400 | $msg | not set | $error |
sayHello() | none | Echoes 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 933RestResponse::warning(...)calls inapp/, only 78 pass a numeric status (most often422, then420,400,404,403,201). The rest return 402 for ordinary business errors such as "Workspace is not available." Frontends checkstatus/codein the body, not only the HTTP status.error()hides the message in production. Whenconfig('app.env') === 'production'the message becomesWhoops! Something went wrong., the exception message, file and line go to thecustomlogchannel (storage/logs/custom.log), andnewrelic_notice_error()runs if the extension is loaded. Outside production the raw exception message is returned. 428 of the 468 calls areRestResponse::error($e->getMessage(), $e)inside acatch.validationError()is normally called asRestResponse::validationError($validate->errors())(182 calls), soerroris the LaravelMessageBagkeyed by field.success()always returns 200.RestResponsehas no pagination helper; whatever the controller passes (array, model, collection or paginator) is placed indataas is.
Responses that do not use the envelope:
| Source | Shape |
|---|---|
Authenticate::unauthenticated() (all auth:* guards) | {"error": "Unauthenticated."}, 401 |
CheckExternalUser middleware | {"error": "Unauthenticated."} 401, or {"error": "Your account is inactive."} 403 |
SsoEntryCheck via VerifyUserWithWorkSpace | Envelope 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 callback | HTTP 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.
| Class | Base | toArray output |
|---|---|---|
CardResource | JsonResource | id, brand, country, customer, cvc_check, dynamic_last4, exp_month, exp_year, fingerprint, funding, last4, name |
InvoiceResource | JsonResource | id, 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) |
PaymentResource | JsonResource | Card: 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, PaymentCollection | ResourceCollection | parent::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 ​
| Field | Rules |
|---|---|
workspace_id | required, exists:workspaces,url_slug |
url | array |
url.0 | required |
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 ​
| Field | Rules |
|---|---|
workspace_id | required, exists:workspaces,url_slug |
forms | required, array |
forms.*.name, forms.*.attr_id, forms.*.attr_name, forms.*.attr_class, forms.*.attr_method, forms.*.attr_action | nullable, string |
forms.*.page_url | required, string |
forms.*.fieldInfo | required, 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_name | nullable, string |
forms.*.fieldInfo.*.attr_multiple | nullable |
forms.*.fieldInfo.*.request_name | required, 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 ​
| Field | Rules |
|---|---|
workspace_id | required, exists:workspaces,url_slug |
name | required, string |
LeadStatusUpdateRequest ​
| Field | Rules |
|---|---|
workspace_id | required, exists:workspaces,url_slug |
status_id | required, 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 ​
| Field | Rules |
|---|---|
workspace_id | required, exists:workspaces,url_slug |
form_ids | nullable, array |
VerifyUrlRequest ​
| Field | Rules |
|---|---|
url | required, 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).