I currently added a new api resource for products (related to user model)
it actually works fine but the result that i retrieve from the POST request is
{
"data": {
"type": "user-products",
"id": "10",
"links": {
"self": "/user-products/10"
},
"attributes": {
"user_id": 1,
"product_title": "Sample Product",
"product_description": "This is a sample product description.",
"product_price": "19.99",
"currency": "USD",
"status": "available",
"createdAt": "2025-01-16T09:12:40+00:00",
"updatedAt": "2025-01-16T09:12:40+00:00"
},
"relationships": {
"user": {
"data": {
"type": "users",
"id": "1"
}
}
}
},
"jsonapi": {
"version": "1.1"
}
}
as you can see i get correctly the user relation, but i want also all the user data, not only the type and the id
here's my resource
public function model(): string
{
return UserProduct::class;
}
public function scope(Builder $query, OriginalContext $context): void
{
$actor = $context->getActor();
$query->where('user_id', $actor->id);
}
public function endpoints(): array
{
return [
Endpoint\Create::make()
->authenticated(),
Endpoint\Update::make()
->authenticated(),
Endpoint\Delete::make()
->authenticated(),
Endpoint\Show::make(),
Endpoint\Index::make()
->paginate()
->limit(30),
];
}
public function fields(): array
{
return [
Schema\Integer::make('user_id')
->requiredOnCreate()
->writable(),
Schema\Str::make('product_title')
->requiredOnCreate()
->writable(),
Schema\Str::make('product_description')
->requiredOnCreate()
->writable(),
Schema\Str::make('product_price')
->requiredOnCreate()
->regex('/^\d+(\.\d{1,2})?$/')
->writable(),
Schema\Str::make('currency')
->requiredOnCreate()
->maxLength(3)
->writable(),
Schema\Str::make('status')
->writable()
->regex('/^(available|sold)$/'),
Schema\DateTime::make('createdAt'),
Schema\DateTime::make('updatedAt'),
Schema\Relationship\ToOne::make('user')
->type('users')
->includable()
];
}
public function sorts(): array
{
return [
SortColumn::make('createdAt'),
];
}
what im doing wrong?