Dinesh Uprety
@dineshuprety ·
Public
Return a JSON:API resource
PHPLaravel 13 API example based on official Laravel documentation. Source: https://laravel.com/docs/13.x/eloquent-resources#json-api-resources
PHP
CodeSnap // free canvas
Return a JSON:API resource
<?php
use Illuminate\Http\Resources\JsonApi\JsonApiResource;
final class PostResource extends JsonApiResource
{
public $attributes = ['title', 'body', 'created_at'];
public $relationships = ['author', 'comments'];
}
return $post->toResource();
// Further reading: https://laravel.com/docs/13.x/eloquent-resources#json-api-resources