PHP code example of eozden / api-response

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

    

eozden / api-response example snippets


response()->ok($data = null, int $code = null);
response()->error($data = null, int $code = null);

public function delete()
{
    User::find(1)->delete();

    return response()->ok();
}

return [

    /**
     * Default response code settings
     */ 
    "default" => [
        "ok" => \Eozden\ApiResponse\ResponseStatus::OK,
        "error" => \Eozden\ApiResponse\ResponseStatus::UNPROCESSABLE_ENTITY,
    ],
    
    /**
     * Force to use middleware to return response as a json
     */ 
    "force" => true,
    
    /**
     * You can add your custom HTTP Status Codes
     */ 
    "map" => [
        \Eozden\ApiResponse\ResponseStatus::OK => "ok",
        \Eozden\ApiResponse\ResponseStatus::CREATED => "created",
        \Eozden\ApiResponse\ResponseStatus::ACCEPTED => "accepted",
        \Eozden\ApiResponse\ResponseStatus::NO_CONTENT => "no_content",
        \Eozden\ApiResponse\ResponseStatus::NOT_MODIFIED => "not_modified",
        \Eozden\ApiResponse\ResponseStatus::BAD_REQUEST => "bad_request",
        \Eozden\ApiResponse\ResponseStatus::UNAUTHORIZED => "unauthorized",
        \Eozden\ApiResponse\ResponseStatus::FORBIDDEN => "forbidden",
        \Eozden\ApiResponse\ResponseStatus::NOT_FOUND => "not_found",
        \Eozden\ApiResponse\ResponseStatus::CONFLICT => "conflict",
        \Eozden\ApiResponse\ResponseStatus::UNPROCESSABLE_ENTITY => "unprocessable_entity",
        \Eozden\ApiResponse\ResponseStatus::INTERNAL_SERVER_ERROR => "internal_server_error"
    ]
];