Laravel API Response api uchun moslangan bo‘lib, mijoz javobni JSON shaklida qaytaruvchi va unga shakl berib jo‘natuvchi kutibxona.
Laravel API Response is a package that helps to provide and render a consistent HTTP JSON responses to API calls as well as converting and formatting exceptions to JSON responses.
- PHP ^8.1
- Laravel ^10 | ^11
Laravel | Laravel API Response |
---|---|
10.x | 1.x |
11.x | 1.2.x |
Install the package via composer:
composer require ijodkor/laravel-api-response
Add RestResponse trait to app module Controller file or any controller which is needed
use Ijodkor\ApiResponse\Responses\RestResponse;
class Controller extends Controller {
use RestResponse;
}
...
class UserController extends Controller {
public function () {
return $this->success([
'user' => new User();
]);
}
}
Nomi (name) | Izoh (description) | Status |
---|---|---|
success | Muvaffaqiyatli | 200 |
created | Muvaffaqiyatli | 201 |
fail | Xatolik yuz berganda | [400] |
error | Ichki xatolik | 500 |
unAuthorized | Manzil ruxsat yo‘q | [401] |
result | Javobda raqam va satrlar moslangan | 200 |
paginated | Sahiflangan ro‘yxat | 200 |
This package also provided RestRequest to return json response Request validations
use Ijodkor\ApiResponse\Requests\RestRequest;
// class UserRequest extends FormRequest - x
class UserRequest extends RestRequest {
}
- Testbench Laravel Testing Helper for Packages Development