In this last lesson, let's check four packages that could be useful when working with APIs.
1. Laravel API Response Helpers
The first package, Laravel API Response Helpers, helps you to standardize responses.
If you return a lot of return response()->json()
, this package might help you. We can install this package via composer.
composer require f9webltd/laravel-api-response-helpers
Then, add trait F9Web\ApiResponseHelpers
to any Controller you want to use helpers. Now, we can use helpers from the package. For example, return a successful response:
use F9Web\ApiResponseHelpers; class ProductController extends Controller{ ApiResponseHelpers; public function index() { $products = Product::with('category')->paginate(9); return responseWithSuccess($products); }}
You can check other helper methods in the official documentation.
You can watch the video version of the package review on YouTube: Laravel Package For Standard API Responses.