Chapters
48 Chapters
|
5:13:28
|
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!
05.
Publishing a Listing
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!
This tutorial also works great with API Platform 2.6.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^2.1", // v2.5.10
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.12.1
"doctrine/doctrine-bundle": "^2.0", // 2.1.2
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.4.5", // 2.8.2
"nelmio/cors-bundle": "^2.1", // 2.1.0
"nesbot/carbon": "^2.17", // 2.39.1
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.0", // 5.2.2
"ramsey/uuid-doctrine": "^1.6", // 1.6.0
"symfony/asset": "5.1.*", // v5.1.5
"symfony/console": "5.1.*", // v5.1.5
"symfony/debug-bundle": "5.1.*", // v5.1.5
"symfony/dotenv": "5.1.*", // v5.1.5
"symfony/expression-language": "5.1.*", // v5.1.5
"symfony/flex": "^1.1", // v1.21.6
"symfony/framework-bundle": "5.1.*", // v5.1.5
"symfony/http-client": "5.1.*", // v5.1.5
"symfony/monolog-bundle": "^3.4", // v3.5.0
"symfony/security-bundle": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/validator": "5.1.*", // v5.1.5
"symfony/webpack-encore-bundle": "^1.6", // v1.8.0
"symfony/yaml": "5.1.*" // v5.1.5
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.3.2
"symfony/browser-kit": "5.1.*", // v5.1.5
"symfony/css-selector": "5.1.*", // v5.1.5
"symfony/maker-bundle": "^1.11", // v1.23.0
"symfony/phpunit-bridge": "5.1.*", // v5.1.5
"symfony/stopwatch": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/web-profiler-bundle": "5.1.*", // v5.1.5
"zenstruck/foundry": "^1.1" // v1.8.0
}
}
11 Comments
Hi, when I launch the unit test for the testPublishCheeseListing I have a strange error NotFoundHttpException: "NotFound". How can your test succeed on the first assertion to fail on the second one when the field isPublished is not modifiable through the api, the first test returns me a 404 response and not a 200, but it is not the case in the video, did I miss something important.
I am on APIP 2.6.8 and Symfony 5.4.6
In the Symfony profiler, I noticed that a first GET request before the PUT request was failing 404, I think it's related to the CheeseListingPublishExtension which only allows to retrieve published items, so the PUT request fails to update an unpublished item because it can't find it and therefore returns a NotFound response.
Is my thinking correct?
Hey gabrielmustiere
You're right about the
CheeseListingPublishExtension, it filters out non-published items unless you're an admin or you're the owner. In this case, we're updating a CheeseListing, so, you need to be the owner. I believe you just forgot to set the owner on the CheeseListing object.Cheers!
I am the owner of this cheese, even a GET on a cheese I own returns me a NotFound response
I solved my problem by looking at this little tip that I had missed: https://symfonycasts.com/sc...
Hey MolloKhan
I have already set the owner on the CheeseListing object, still getting the same 404 error! Any help!?
Hello,
I would like to know how to do this endpoint:
`POST /api/cheeses/{id}/publish.`
and I'm asking if create a custom controller https://api-platform.com/do... it's the right way?
Thanks for your answer and thank you for your excellent work!
Hey @paralucia!
Ah, we didn't convince you to do the RESTful approach in this tutorial? Fair enough 😉
We'll talk about this in the next tutorial, but any solution is fine. I would personally probably prefer the Messenger integration first, and the custom controller as the second option, but do what works for you.
Cheers!
Haha ! Yes, you convinced me, but I was so curious so I asked you!
Thank you for your rapid answer !
"Houston: no signs of life"
Start the conversation!