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
}
}
28 Comments
If you are also running into this error:
removing 'doctrine/annotations' might fix it:
To fix this I changed the composer.json to include "minimum-stability": "beta". Then I did a
composer update.Hey FR,
At what point did you get that error? Did you download the course code, or you're following the course by yourself?
I did download the course code and coded along. The error popped up in this chapter or the end of the last chapter.
Hey @FR!
There definitely IS some weird stuff happening right now, as the ecosystem transitions away from annotation - e.g. https://github.com/symfony/symfony/issues/48792
But I can't get this to repeat using the code - I've tried doing
composer installon thefinishcode as well as acomposer update. We MIGHT have a dependency that needs upgrading, but I can't trigger it. @FR - do you see the error when you runcomposer instalor do you need to actually use an endpoint?Thanks!
Thank you for the course!
You're welcome!
Hey there!
First of all, thanks for your nice Videos!
Really having fun here :)
Except, when it comes to ReactAdmin...
I tried it two times now with setting up the whole api from scratch (had to downgrade doctrine/orm to 2.18, because apparently 3.00 cant handle ManyToMany Relationsships anymore), BUT
I always get a white screen!
Apparently, react does something, if I inspect my element, this is what it looks like:
This is my twig template:
My ReactAdmin:
The only difference was, that I was using @babel/preset-react: 7.0.0 instead of 7.18.6
I tried to update the version, npm install, but still: white screen.
I see a loading circle for a short moment and I can see, that the system made 3 Ajax Requests:
/api
/api/docs.jsonld
/api/contexts/Entrypoint
You got any idea, how I can get it to work?
Thanks and greetings
Maik
Hey @Maik-D!
Apologies for my epically slow reply!
Hmm. Let's look through piece-by-piece:
This tells me that you're outputting the right stuff. And the fact that you see the 3 AJAX requests is what really convinces me that React has, at least, started. But no errors and nothing else on the page? Tbh, I can't think of how the
HydraAdminwould obviously start (HydraAdmincode is what makes those Ajax calls)...but then it doesn't do anything or show an error. Do the responses in those 3 Ajax calls look correct? Can you see that they're all returning JSON?Cheers!
Hi Everybody :)
First, I would like to thank you for this superb course.
Everything went good for me, except the last step,
npm install @babel/react-preset@^7.0.0 --save-devDidn't work : '@babel/react-preset@7.0.0' is not in this registry,
so I ran :
npm install @babel/preset-react@^7.0.0 --save-devThen, when loading the admin page, I got several JS errors/warnings, here are the first two logs :
which I couldn't resolve
Any idea ? I am on Symfony 6.2.14 by the way.
Thanks in advance :)
Hey @Hamza-Y!
Yikes! That is a huge, ugly error. To be honest, I have no clue what's gong on :/. I'd recommend running
npm outdatedto, perhaps, see if any packages are out-of-date. This certainly feels like different packages of different versions not playing nicely with each other - but I'm guessing.Sorry I can't be more helfpul!
Sadly the Hydra Admin is actually not working in Symfony 7.0.1, i also tested out 6.4 but i had still no luck setting it up there :(
Starting the moment an Entity has been added to the Api Platform (which works on the PHP site well) the Hydra Admin is crashing after loading.
Hey @Sebastian
Forgive my ignorance but is the Hydra Admin a project of ApiPlatform? Perhaps you could create an issue on their GitHub repository
Cheers!
I think that the React Admin from api-platform/admin is based on HydraAdmin (correct me if im wrong). I tested both because i wanted to know if the base of it makes the problem or api-platform/admin itself :)
If someone wants a (temporary) solution, here is a way to fix it:
https://github.com/api-platform/admin/issues/522
Yes, I think you're right.
It's a weird error, I don't know what could be the issue, but thank you for sharing a workaround!
Cheers!
Hey, React Admin is so cool, thanks for introducing it in this amazing course!
I am adopting it now, and I found out that HMR is currently NOT supported for React out of the box. I had to do some research to make it work with Symfony + Webpack Encore + React, and I wanted to share it here to help others save time and efforts.
What you need is React Refresh Webpack Plugin: https://github.com/pmmmwh/react-refresh-webpack-plugin/. Here's how to set it up with Webpack Encore:
If you use Symfony local webserver with SSL, you also need to enable HTTPS for
webpack-dev-server, otherwise you'll see error in the browser's console about refresh plugin not being able to connect to websocket:NOTE: this is the setup without Stimulus Bridge.
Ah, this is awesome! Thanks for sharing this - seriously!!
I am quite sure I'll come here myself a lot of times in the future after googling "how to enable HMR for react"😂
Hi, i'm user a project with Symfony 6.3.1, all work fine, but in ReactAdmin i have this error on my console :
I found the problem, i added my 2nd ApiResource before the first on my DragonTreasure class. I know now we have to add ApiResource AFTER the first one
Thank you for sharing your solution. Cheers!
Congratulations. One more masterpiece. Keep up excellent work.
Yo! Thanks for feedback we really appreciate it!
Cheers and Happy coding!
Hello!
In my admin panel when I go to create a user it only requires the username but not the password and the email, also when I want to create or modify an object it always gives me the error 422 because one of my assertions jumps without me having touched that field.
Any ideas?
Hi @Fran!
Hmm.
Do you mean that it doesn't show your email / password fields? Or that it shows them, but they are not required?
What do you mean by "the assertion jumps"?
But, I can maybe give some hints :). If you haven't done it already,
passwordwill need a validation group to be added - https://symfonycasts.com/screencast/api-platform-security/validation-groups - so that it isn't always required. This may or may not be your issue, but I wanted to mention it :).Cheers!
Hello,
How can i fetch owner(data who owner is email from token) data if i use JWT token ?
Regards.
Mmx
Hey @Mepcuk!
So you have a JWT and that JWT contains the
emailof the user? Is that correct? We'll talk closer to this use-case (though not this exactly) in the next tutorial. But I would:A) Use the new
access_tokensystemB) In the "access token handler" class you'll create, you'll decode the JWT to get the email
C) Then, return
new UserBadge($email). As long as your have an "entity" user provider insecurity.yamlset up to query from theemailproperty... that's all you need.Let me know if that helps :).
Cheers!
Hey @weaverryan!
I think you did not understand my question - I have a Get operation -
It's work perfect and i can get information if i know ID :))) If not resricted.
But i want to make resourse where i can get all data (relations) related to this user (i login via JWT token)
I try to get Collection but it not worked
Security key did not described in API=platform docs and i don't know how to fetch collection assigned-related to user with this JWT token. You told that in security: possible to write user check, but how?
Hey @Mepcuk!
Haha, that happens to me a lot - apologies :)
Let's see... Question: how are you using
GetCollectionoperation? Are you using anApiFilterto filter by email - e.g./api/loans?email=foo@example.com? Or something else?When you use a
GetCollectionendpoint, the actual "object" is not, of course, a singleLoanPersonobject, but an array (or technically aCollection) orLoanPersonobjects. You tried usingcollection.getEmail()- but I don't quite understand yet what you were trying to do.You also said:
If I understand correctly, you would like to be able to make a
GET /api/loansand receive back only the loans "owned" by the currently-authenticated user. Is that correct? If so, solving this is less about security and more about filtering the data (from a security perspective, all users will have access to fetch their collection of loans, but they should only see their own loans). For this, I would use a "query extension" - https://symfonycasts.com/screencast/api-platform-security/query-extension - to automatically filter this. It doesn't matter that the user is inside of a JWT. It only matters that you fetch the currently-authenticated user, then modify the query based on that user inside the query extension.Let me know if I was closer this time :)
Cheers!
"Houston: no signs of life"
Start the conversation!