Fresh code drop

Return a JSON:API resource

PHP

Laravel 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

Turn your code into a post.Five templates are free—no account needed.

Remix this snap