PHP code example of litermi / response

1. Go to this page and download the library: Download litermi/response library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

litermi / response example snippets


'providers' => [
    // ...
    Litermi\Response\Providers\ServiceProvider::class,
],

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

    //.
    //.
    //.
}

sh
php artisan vendor:publish --provider="Litermi\Response\Providers\ServiceProvider"