PHP code example of cerenimo / laravel-responses

1. Go to this page and download the library: Download cerenimo/laravel-responses 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/ */

    

cerenimo / laravel-responses example snippets


composer 

use Cerenimo\LaravelResponses\Response;

class YourClass {

use Response;
// ...
}
 
return $this->setMessage('successfully')
->responseSucces();

{
    "result": true,
    "message": "successfully"
}

        $this->setCustomData('user', $user)
        ->setCustomData('token', $token)
        ->setMessage('User Created')
        ->setStatusCode(201)
        ->responseSuccess(); 
    

        $this->responseSuccess();
    

        $this->setMessage('Successfully!')->responseSuccess();
    

    {
        "result": true,
        "message": "User Created",
        "data": {
            "user": {
                "id": 372,
                "name": "Ceren Özkurt"
            },
            "token" : "Bfafa98a7f8afkafafaf98afajfka"
        }
    }
    

        $this->setPagination($setPagination)
        ->setDataName('files')
        ->responseDataWithPagination(); 
    

    {
        "result": true,
        "data": {
            "files": [
                {
                    "id": 60,
                    "userId": "auth0|64a7fd7bc8e7f423cb5285b2",
                    "filename": "seller-288138-barkod-bazlı-iade-raporu-2023.05.03-18.19.04.xlsx",
                    "fullPathName": "/home/rontest/public_html/uploads/64a7fd7bc8e7f423cb5285b2/1688731195_jaTuvvO7dSrFzcJy.xlsx",
                    "type": "excel",
                    "createdAt": "2023-07-07T11:59:55.000000Z",
                    "updatedAt": "2023-07-07T11:59:55.000000Z"
                },
                {
                    "id": 59,
                    "userId": "auth0|64a7fd7bc8e7f423cb5285b2",
                    "filename": "Ağrı Dağı Efsanesi .pdf",
                    "fullPathName": "/home/rontest/public_html/uploads/64a7fd7bc8e7f423cb5285b2/1688731130_74bI3pGXa9yq7Fda.pdf",
                    "type": "pdf",
                    "createdAt": "2023-07-07T11:58:50.000000Z",
                    "updatedAt": "2023-07-07T11:58:50.000000Z"
                }
            ]
            },
            "page": {
                "links": {
                    "first": true,
                    "last": true,
                    "prev": null,
                    "next": null
                },
                "meta": {
                    "current_page": 1,
                    "from": 1,
                    "to": 2,
                    "per_page": 25,
                    "total": 2
                }
            }       
    }

    

        $this->setMessage('Failed')
        ->setStatusCode(400)
        ->responseError(); 
    

        $this->responseError(); //default message and status code
    

        $this->setMessage('Failed!')
        ->responseSuccess();
    

    {
        "result": false,
        "message": "Failed",
    }
    

        $this->setValidation($validation)
        ->responseValidation(); 
    

    {
        "result": false,
        "validation_error": {
            "name": [
                "The name field is 

        $this->setMessage('Failed')
        ->responseNotFound(); 
    

        $this->responseNotFound(); 
    

    {
        "result": false,
        "error": "Failed"
    }
    

        $this->setMessage('No Permission')
        ->responseForbidden(); 
    

        $this->responseForbidden(); 
    

    {
        "result": false,
        "error": "No access permission."
    }
    

        $this->setMessage('No Authorized')
        ->responseUnauthorized(); 
    

        $this->responseUnauthorized(); 
    

    {
        "result": false,
        "error": "Not authorized."
    }
    

        $this->setException($e)
        ->responseTryCatch(); 
    

    {
        "result": false,
        "error": "sql connection error"
    }
    

        $this->setMessage('Failed')
        ->responseValidation(); 
    

        $this->responseValidation(); 
    

    {
        "result": false,
        "error": "Failed"
    }
    

        $this->setMessage('Failed')
        ->responseBadRequest(); 
    

        $this->responseBadRequest(); 
    

    {
        "result": false,
        "error": "Bad request."
    }
    

        $this->setMessage('Failed')
        ->responseConflict(); 
    

        $this->responseConflict(); 
    

    {
        "result": false,
        "error": "Conflict."
    }
    

        $this->setMessage('Failed')
        ->responsePayloadTooLarge(); 
    

        $this->responsePayloadTooLarge(); 
    

    {
        "result": false,
        "error": 'Payload too large.'
    }
    

        $this->setMessage('Failed')
        ->responseTooManyRequests(); 
    

        $this->responseTooManyRequests(); 
    

    {
        "result": false,
        "error": "Too many requests."
    }
    

        $this->setMessage('Failed')
        ->responseInternalServer(); 
    

        $this->responseInternalServer(); 
    

    {
        "result": false,
        "error": 'Internal server error.'
    }
    

        $this->setMessage('Failed')
        ->responseNotImplemented(); 
    

        $this->responseNotImplemented(); 
    

    {
        "result": false,
        "error": 'Not implemented.'
    }
    

        $this->setMessage('Failed')
        ->responseInvalidToken(); 
    

        $this->responseInvalidToken(); 
    

    {
        "result": false,
        "error": 'Invalid token.'
    }