PHP code example of spatie / laravel-endpoint-resources
1. Go to this page and download the library: Download spatie/laravel-endpoint-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/ */
spatie / laravel-endpoint-resources example snippets
php
class UserResource extends JsonResource
{
use Spatie\ResourceLinks\HasLinks;
use Spatie\ResourceLinks\HasMeta;
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'links' => $this->links(UsersController::class),
];
}
public static function meta()
{
return [
'links' => self::collectionLinks(UsersController::class),
];
}
}