ilyatos/laravel-api-response is a Laravel package for give it to me as json!.
It currently has 0 GitHub stars and 0 downloads on Packagist.
Install it with composer require ilyatos/laravel-api-response.
Discover more Laravel packages by ilyatos
or browse all Laravel packages to compare alternatives.
Last updated
Welcome to simple wrapper of JsonResponse!
You don't need to register the service provider manually.
All you need to do is inject the \Ilyatos\ApiResponse\Contracts\Response interface into your controller/middleware/etc. constructor.
Just look at this nice example and everything will be clear for you:
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller as BaseController;
use Ilyatos\ApiResponse\Contracts\Response;
class Controller extends BaseController
{
/**
* @var Response
*/
protected $response;
public function __construct(Response $response)
{
$this->response = $response;
}
public function example(): JsonResponse
{
return $this->response->withMessage('hello!');
}
public function anotherExample(): JsonResponse
{
return $this->response->withDefaultMessage(\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND);
}
public function yetAnotherExample(): JsonResponse
{
return $this->response->withData(['status' => 'nice']);
}
}