Download the PHP package quonain/smart-response without Composer

On this page you can find all versions of the php package quonain/smart-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package smart-response

SmartResponse

Latest Version on Packagist License PHP Version

SmartResponse is a production-ready Laravel package that returns API JSON or Blade / Inertia web views from the same controller method — with automatic request-type detection.


Table of contents


Features

Category Capabilities
Detection Accept header, expectsJson(), /api/* routes, Bearer tokens (Sanctum / Passport)
API Standard JSON envelope, optional XML, validation errors, exception handler
Web Blade views, redirects, session flash, optional toast
Pagination Length-aware, simple, cursor paginators + API Resources
DX Trait, Facade, global helpers, response()->smart* macros
HTTP shortcuts created, noContent, notFound, unauthorized, forbidden
Meta Auto timestamp, request_id, optional api_version on API responses
Extras Inertia.js, Livewire, i18n, caching, logging, events, OpenAPI examples
Framework Laravel 10 · 11 · 12 · 13 · PHP 8.2+

Requirements


Installation

Or pin the latest 1.x release:

Laravel auto-discovers the service provider — no manual registration.

Publish assets

Packagist: After a new release, open your package page and click Update if Composer does not see the latest tag yet. Enable the GitHub hook under package settings for automatic sync.


Quick start

1. Add the trait

Request type Result
API (Accept: application/json, /api/*, Bearer token, …) Standard JSON
Web (text/html, normal browser) Blade view users.index with $data, $message, …

2. Default JSON shape


How API vs Web is detected

SmartResponse treats a request as API when any of these match (configurable in config/smart-response.php):

  1. Accept contains application/json or application/vnd.api+json
  2. Accept contains application/xml or text/xml
  3. Route matches api/* or configured prefixes (api by default)
  4. Laravel expectsJson() is true (AJAX, etc.)
  5. Authorization: Bearer … is present (detection.bearer_as_api — ideal for Sanctum / Passport SPA or mobile apps)

Otherwise the request is handled as Web (view or redirect).


Usage

Unified smartResponse()

HTTP shortcuts

Trait method Facade / Manager Status Use case
smartSuccess() SmartResponse::success() 200 OK with data
smartCreated() SmartResponse::created() 201 Resource created
smartNoContent() SmartResponse::noContent() 204 Delete / empty OK
smartError() SmartResponse::error() 4xx/5xx Generic error
smartNotFound() SmartResponse::notFound() 404 Missing resource
smartUnauthorized() SmartResponse::unauthorized() 401 Not logged in
smartForbidden() SmartResponse::forbidden() 403 No permission
smartValidationError() SmartResponse::validationError() 422 Form / API validation

Facade & global helpers

Response macros

Pagination

Length-aware — pass a paginator; meta keys are merged automatically:

Cursor — works with cursorPaginate():

Meta includes: per_page, path, next_cursor, prev_cursor, has_more.

API Resources & XML

API meta enrichment

Enabled by default (meta.enabled in config). Every API response can include:

Meta key Source
timestamp Current time (ISO 8601)
request_id X-Request-Id header or auto UUID
api_version X-API-Version header or meta.api_version config

Rate limiting

Returns a standard error JSON with Retry-After header:

Caching (API)

Enable in config, then cache GET API responses:

Without cacheKey, a hash of the full URL + Accept header is used.

Web redirect with flash & toast


Exception handling (API)

Register in bootstrap/app.php (Laravel 11+):

API requests receive the same JSON envelope; web requests fall through to Laravel’s default handling.


Configuration

Publish config/smart-response.php and adjust:

Key Description
api.* JSON keys: success, message, data, meta, errors
detection.* JSON/XML accepts, route prefixes, bearer_as_api
meta.* Timestamp, request ID, API version injection
default_format json or xml
status_codes.* Defaults for 200, 201, 204, 401, 403, 404, 422, 429, 500
web.* Flash / toast session keys, default redirect route
inertia.enabled Inertia.js adapter
livewire.enabled Livewire hooks
locale.enabled Translate message keys via lang files
cache.enabled Cache GET API responses
logging.enabled Log each response
events.enabled SmartResponsePreparing / SmartResponsePrepared
rate_limit.* 429 message and retry_after_seconds
graphql.enabled GraphQL response Accept detection

Multi-language messages

Built-in keys include: users.fetched, users.created, error.not_found, error.unauthorized, error.forbidden, error.rate_limit, and more.

Inertia.js


Middleware

Alias: smart.response (enabled by default)

Events

OpenAPI / Swagger


Testing


Package structure


Changelog

See CHANGELOG.md for version history (1.1.0 — HTTP shortcuts, meta enrichment, cursor pagination, Bearer detection).


Contributing

See CONTRIBUTING.md.


License

MIT © Quonain Ejaz. See LICENSE.


All versions of smart-response with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package quonain/smart-response contains the following files

Loading the files please wait ...