quonain/smart-response
SmartResponse is a Laravel package that returns JSON API responses or Blade/Inertia views from the same controller method, auto-detecting request type (Accept header, /api routes, bearer tokens). Includes pagination, response shortcuts, macros, caching, and meta enrichment.
/api/* routes) and web views seamlessly, reducing cognitive load for developers.Response class, ensuring no forced refactoring.Accept header, expectsJson()), reducing custom logic.spatie/laravel-api)./api/* vs. web routes) align with existing middleware (e.g., api middleware group)?spatie/laravel-api) that enforce API-specific behaviors?Cache::remember)?Accept headers)?Illuminate\Http\Response, Illuminate\Support\Facades\Response, and Illuminate\Routing components./api/* with JSON responses (e.g., SPAs, mobile apps).expectsJson(), Route::apiResource()).inertiajs/inertia-laravel (for SPA integration) or spatie/laravel-api (for API-specific middleware).return response()->json(...) and return view(...) with return SmartResponse::make(...).SmartResponse for isolated controller testing.return view() in API controllers) via deprecation warnings./api/* routes are explicitly marked (e.g., Route::prefix('api')->group(...)) to avoid misclassification.config/smart-response.php if using non-standard headers (e.g., X-Requested-With).throttle, auth) to confirm no interference with request-type detection.SmartResponse::withoutDetection() for endpoints requiring manual control.inertiajs/inertia-laravel (for SPA responses).spatie/laravel-api (if enforcing API-specific middleware).fruitcake/laravel-cors (for CORS headers in API responses).composer require quonain/smart-response.php artisan vendor:publish --provider="Quonain\SmartResponse\SmartResponseServiceProvider".SmartResponse::make().Response::macro('error', ...)).SmartResponse::cache()).config/smart-response.php.SmartResponse::error()) reduces debugging complexity.SmartResponse::debug()) to troubleshoot misclassified requests.Cache::remember).SmartResponse::throttle()) scales with traffic.Accept headers).SmartResponse::forceJson() or forceView() for critical endpoints.SmartResponse::withoutMacros() to debug.spatie/laravel-api).SmartResponse::make()).How can I help you explore Laravel packages today?