I created an API with the Laravel-json-api framework, with no controller, since the framework do all the job.
It works fine with index and read, not with update.
I use Postman to do an update, but it returns the record in the DB, without any change, nor any error message.
the api.php file :
JsonApi::register('v1')->routes(function ($api) {
$api->resource('titre')->only('index', 'read', 'update');
});
To update the titre record, I use /localhost/api/v1/titre/777777
I use Postman, with the right Content-Type : application/vnd.api+json
And here is my Postman's raw body :
{
"data": {
"type": "titre",
"id": "777777",
"attributes": {
"ACTIF": "O",
},
"links": {
"self": "http://localhost/api/v1/titre/777777"
}
}
}
I expect the API to update the ACTIF attribute, but I get as a result :
{
"data": {
"type": "titre",
"id": "777777",
"attributes": {
"ACTIF": "D",
},
"links": {
"self": "http://localhost/api/v1/titre/777777"
}
}
}
No error message, or anything, but the ACTIF attribute, which should be updated from D to O, is not updated.
According to the Laravel-json-api documentation, this should work, right ? Can someone tells me where is my error ?
What you are facing might be caused by several reasons. Please check these points:
PATCH
HTTP method for updates. JSON:API specification explicitly requires PATCH
for updates.ACTIF
attribute is fillable if you are using Eloquent Adapter. Laravel JSON API relies on mass assignment feature.If this doesn't work, please include a curl
request in your question as it helps us to reproduce your request.