1. Go to this page and download the library: Download iqbalatma/laravel-utils 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/ */
namespace App\Http\Controllers\API\Internal\Management;
use App\Http\APIResponse;
use App\Http\Controllers\ApiController;
use App\Models\Permission;
use App\Http\Resources\Internal\Management\Permissions\PermissionResourceCollection;
class PermissionController extends ApiController
{
/**
* @return APIResponse
*/
public function index(): APIResponse
{
$data = Permission::all();
return $this->response(
new PermissionResourceCollection($data),
"Get all data permission successfully"
);
}
}
namespace App\Services\V1;
use Iqbalatma\LaravelUtils\Interfaces\ResponseCodeInterface;
use Symfony\Component\HttpFoundation\Response;
/**
* @method static ResponseCodeInterface ERR_NOT_FOUND()
*/
class ResponseCode extends \Iqbalatma\LaravelUtils\ResponseCode
{
protected const ERR_NOT_FOUND = "ERR_NOT_FOUND";
/**
* @return void
*/
protected function mapHttpCode(): void
{
$this->httpCode = match ($this->name) {
self::ERR_NOT_FOUND => Response::HTTP_NOT_FOUND,
default => null
};
if ($this->httpCode === null) {
parent::mapHttpCode();
}
}
}
$this->renderable(function (NotFoundHttpException $e) {
if (request()->expectsJson()) {
return new APIResponse(
null,
message: $e->getMessage(),
responseCode: ResponseCode::ERR_NOT_FOUND(),
exception: $e
);
}
});