/laravel-api-response

Laravel uchun (api) javoblar to'plami

Primary LanguagePHP

Laravel API Responses

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.

Talablar (Requirements)

  • PHP ^8.1
  • Laravel ^10 | ^11

Talqinlar mutonosibligi (Version Compatibility)

Laravel Laravel API Response
10.x 1.x
11.x 1.2.x

O‘rnatish (Installation)

Install the package via composer:

composer require ijodkor/laravel-api-response

Ishlatish (Usage)

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();
        ]);
    }
}

Mavjuda funksiyalar (Available functions)

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

Sovg‘a (Bonus)

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 {

}

Foydalanilgan manbalar (References)

  • Testbench Laravel Testing Helper for Packages Development

Foydali havolalar (Links)