1. Go to this page and download the library: Download ayd/api-response-base 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/ */
use Ayd\ApiResponseBase\Contracts\AbilitiesResolver;
class MyAbilitiesResolver implements AbilitiesResolver
{
public function resolve(mixed $user = null): array
{
return [
'create' => $user?->can('create') ?? false,
'delete' => $user?->can('delete') ?? false,
];
}
}
use Ayd\ApiResponseBase\Concerns\BuildsApiResponse;
class MyService
{
use BuildsApiResponse;
public function handle()
{
$meta = $this->buildMeta(); // auto-generates request_id, auto-resolves abilities
$meta = $this->resolveAbilitiesMeta($user); // resolve for a specific user
}
}