PHP code example of sinema / json-api-error

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

    

sinema / json-api-error example snippets




use Sinemah\JsonApi\Error\Error;
use Sinemah\JsonApi\Error\ErrorBag;

$errors = new ErrorBag();

$errors->add(
    Error::fromArray(
        [
            'status' => 404,
            'source' => null,
            'title' => 'Item not found',
            'detail' => sprintf('Item %s not found', 'some-id'),
        ]
    )
);

$errors->toArray()



use Sinemah\JsonApi\Error\Error;
use Sinemah\JsonApi\Error\Response;

$response = Response::get();

$response->add(
    Error::fromArray(
        [
            'status' => 404,
            'source' => null,
            'title' => 'Item not found',
            'detail' => sprintf('Item %s not found', 'some-id'),
        ]
    )
);

$response->toArray()