webappid / smartresponse
SmartResponse simplifies consistent response handling in Laravel: supports Blade, redirect with messages, and JSON format.
3.2.4
2025-08-09 19:08 UTC
Requires
- php: >=8.0
- laravel/framework: ^12.0
README
SmartResponse is a lightweight Laravel helper library that simplifies returning consistent responses, whether in JSON format for APIs or HTML rendered via Blade views. Itβs perfect for APIs and controller logic that need smart decision-making for response formats.
π¦ Installation
Install via Composer:
composer require webappid/smartresponse
π Usage Examples
β Return a JSON Success Response
Use this when building API endpoints that return JSON:
use Illuminate\Http\Request; use WebAppId\SmartResponse\SmartResponse; class SampleController { public function store(Request $request, SampleService $service, SmartResponse $smartResponse) { try { $data = $service->create($request->all()); return $smartResponse->created($data, 'Sample created'); } catch (\Throwable $e) { return $smartResponse->handle($e); } } }
Response Output:
{ "status": "success", "response": { "message": "Sample created", "data": { // Your request data }, "records_filtered": 0, "records_total": 0, "meta": null } }
π¬ Support
If you have any questions or feedback about this package, feel free to reach out:
- π§ Email: dyan.galih@gmail.com
- π¬ Telegram: @DyanGalih
π§ Happy Coding
SmartResponse helps you keep your controller code clean, consistent, and flexible.
Happy coding with SmartResponse!