Chapters
28 Chapters
|
2:51:42
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^3.0", // v3.0.8
"doctrine/annotations": "^1.0", // 1.14.2
"doctrine/doctrine-bundle": "^2.8", // 2.8.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.14", // 2.14.0
"nelmio/cors-bundle": "^2.2", // 2.2.0
"nesbot/carbon": "^2.64", // 2.64.1
"phpdocumentor/reflection-docblock": "^5.3", // 5.3.0
"phpstan/phpdoc-parser": "^1.15", // 1.15.3
"symfony/asset": "6.2.*", // v6.2.0
"symfony/console": "6.2.*", // v6.2.3
"symfony/dotenv": "6.2.*", // v6.2.0
"symfony/expression-language": "6.2.*", // v6.2.2
"symfony/flex": "^2", // v2.2.4
"symfony/framework-bundle": "6.2.*", // v6.2.3
"symfony/property-access": "6.2.*", // v6.2.3
"symfony/property-info": "6.2.*", // v6.2.3
"symfony/runtime": "6.2.*", // v6.2.0
"symfony/security-bundle": "6.2.*", // v6.2.3
"symfony/serializer": "6.2.*", // v6.2.3
"symfony/twig-bundle": "6.2.*", // v6.2.3
"symfony/ux-react": "^2.6", // v2.6.1
"symfony/validator": "6.2.*", // v6.2.3
"symfony/webpack-encore-bundle": "^1.16", // v1.16.0
"symfony/yaml": "6.2.*" // v6.2.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.2
"symfony/debug-bundle": "6.2.*", // v6.2.1
"symfony/maker-bundle": "^1.48", // v1.48.0
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/stopwatch": "6.2.*", // v6.2.0
"symfony/web-profiler-bundle": "6.2.*", // v6.2.4
"zenstruck/foundry": "^1.26" // v1.26.0
}
}
4 Comments
At 45 second of the video, it didn't work as expected in my code, it's throwing error.
When I send this in PATCH request, to add treasure for user with id of 15,
I get 500 Error: Also one more thing I noticed is that PUT doesn't work here at the end of video, I just tried PATCH and it works, like when sending treasures IRI using PATCH, the previously linked treasures get deleted and only new one specified during PATCH request is available on database
{
"@id": "/api/users/15",
"dragonTreasures": [
]
}
The Error:
{
"@id": "/api/errors",
"@type": "hydra:Error",
"title": "An error occurred",
"detail": "An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'owner_id' cannot be null",
Hey @sujal_k
ApiPlatform changed the PUT behavior after this tutorial was released. The PUT operation now works as full update of the resource (you need to send all the fields), and PATCH works to update only the submitted fields
Here's a video where Ryan talks about this change https://symfonycasts.com/screencast/api-platform-security/new-put-behavior
Cheers!
Hey there,
I'm a bit confused, my user put doesn't have a list of IRIs but a list of objects. I don't know if I missed something.
Looking at your DragonTreasure.php file, I feel like you should too.
Anyway, I removed the user:write group from my DragonTreasure's properties, but this is confusing.
Cheers
Hey Julien!
Sorry for the slow reply - we had a hiccup in our notification system!
Just to be totally clear, when I make a
PUTrequest, for thedragonTreasuresproperty, I am:A) SENDING an array of IRI strings
B) RECEIVING an array of objects
Let's look at each side more deeply (probably some of this you already understand, but just to be safe):
A) Since we're writing to
User, theuser:writegroup is being used.DragonTreasureDOES haveuser:writeabovenameandvalue. So, should we be sending an object instead of IRI strings? The answer is that, because those 2 fields haveuser:write, we have the OPTION to send an "object" to thedragonTreasuresproperty, but we're not forced to. We showed that off in an earlier chapter where we even sent a mixture or objects and IRI strings: https://symfonycasts.com/screencast/api-platform/collections-create#sending-embedded-objects-and-iri-strings-at-the-same-timeB) We are using the
PUToperation. But at this point, we're now talking about what data to RETURN. So that is "normalization". And so, the group that's used here isuser:read. Once again, insideDragonTreasure, bothnameandvaluehave this group. And so, the response contains an array of objects fordragonTreasures.Let me know if that helps :)
Cheers!
"Houston: no signs of life"
Start the conversation!