PHP code example of nnjeim / respond

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

    

nnjeim / respond example snippets


php artisan vendor:publish --provider="Nnjeim\Respond\RespondServiceProvider"

use Nnjeim\Respond\RespondHelper;

private RespondHelper $respond;
private array $data;
private bool $success;

public function __construct(RespondHelper $respond)
{
	$this->respond = $respond;
}
.
.
.
$respond = $this
		->respond
		->toJson()
		->setMessage('countries')
		->setData($data);

if ($this->success)
{
	return $respond->withSuccess()
}

return $respond->withErrors();

Sets the response data array.

@return $this       setData(array $data)

Sets the response errors.

@return $this       setErrors(array $errors)