1. Go to this page and download the library: Download zhylon/api-resources 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/ */
zhylon / api-resources example snippets
use Illuminate\Http\Resources\Json\JsonResource;
use Zhylon\ApiResources\Http\Resources\BuildsApiResource;
class OrderResource extends JsonResource
{
use BuildsApiResource;
public function toArray($request): array
{
return $this->toApiResource(
type: 'order',
attributes: [
'status' => $this->status,
'total' => $this->total,
],
selfHref: route('orders.show', $this->resource),
timestamps: true,
);
}
}
use Illuminate\Http\Resources\Json\JsonResource;
use Zhylon\ApiResources\Http\Resources\BuildsApiResource;
class OrderResource extends JsonResource
{
use BuildsApiResource;
protected function resolveResourceId(): string|int|null
{
return $this->resource->uuid;
}
// ...
}
use Zhylon\ApiResources\Http\Resources\ApiResourceCollection;
class OrderCollection extends ApiResourceCollection
{
public function __construct($resource)
{
parent::__construct($resource, OrderResource::class);
}
}
return new OrderCollection(Order::paginate());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.