litermi / response
The Response is a package to response api-rest .
1.0.21
2024-06-07 13:51 UTC
Requires
- php: ^7.4|^8.0
- guzzlehttp/guzzle: ^6.3.1|^7.0.1
- illuminate/config: ^7.20|^8.19|^9.0|^10.0|^11.0
- illuminate/contracts: ^7.20|^8.19|^9.0|^10.0|^11.0
- illuminate/database: ^7.20|^8.19|^9.0|^10.0|^11.0
- illuminate/http: ^7.20|^8.19|^9.0|^10.0|^11.0
- litermi/error-notification: ^1.0
- litermi/logs: ^1.0
README
About
The Response
is a package to response api-rest .
Tutorial how create composer package
Installation
Require the litermi/response
package in your composer.json
and update your dependencies:
composer require litermi/response
Configuration
set provider
'providers' => [ // ... Litermi\Response\Providers\ServiceProvider::class, ],
The defaults are set in config/response.php
. Publish the config to copy the file to your own config:
php artisan vendor:publish --provider="Litermi\Response\Providers\ServiceProvider"
Note: this is necessary to you can change default config
Usage
use Litermi\Response\Traits\ResponseTrait; class Controller extends BaseController { use ResponseTrait; //. //. //. }
Class ProductController extends Controller { //. //. //. public function store(ProductRequest $request){ $successMessage = _('OPERATION_SUCCESSFUL_MESSAGE'); $errorMessage = _('AN_ERROR_HAS_OCCURRED_MESSAGE'); try { DB::beginTransaction(); $product = new Product(); $product->fill($request->validated()); $product->save(); DB::commit(); $data[ 'product' ] = new ProductResource($product); return $this->successResponseWithMessage($data, $successMessage, Response::HTTP_CREATED); } catch(Exception $exception) { DB::rollBack(); return $this->errorCatchResponse($exception, $errorMessage, Response::HTTP_SERVICE_UNAVAILABLE); } } //. //. //. }
License
Released under the MIT License, see LICENSE.