1000 search results

Decorating the CollectionProvider

…the failed response. Hmm: More than one result was found for query, although one row or none was expected. If you view the page source, this is coming from Doctrine... and eventually the core ItemProvider that we're calling. Back on the docs, the GetCollection…

7:12
Setup & Ways to Extend API Platform

…validation, voters, and more. That's all good stuff. But, so far, all of our #[ApiResource] classes have been Doctrine entities. And that's fine! But as your API starts to look different from your entities, making that work adds complexity: serialization groups, extending normalizers…

4:39
Persisting to the Database

…question! We're only going to focus on creating objects and saving them. Doctrine will handle the insert queries for us. To help do this in the simplest way possible, let's make a fake "new Vinyl Mix" page. In the src/Controller/ directory, create…

6:43
MakerBundle & Autoconfiguration

…Ooh. There's a ton of stuff here for setting up security, generating doctrine entities for the database (which we'll do in the next tutorial), making a CRUD, and much more. Let's try one: how about we try to build our own new…

4:27
Activating 2FA

…good. No surprises, it adds one column to our table. Run that: symfony console doctrine:migrations:migrate Here's the plan. A user will not have two-factor authentication enabled by default. Instead, they'll activate it by clicking a link. When they do that…

5:34
stateOptions + entityClass Magic

…darn it, let's yolo this thing and try to! Head over to UserApi, say provider, and point to CollectionProvider (the one from Doctrine ORM). Let's see what happens! At the browser, go to the endpoint directly - /api/users.jsonld. And... we get an…

10:07
State Processors: Hashing the User Password

…platform: we need some way to run code after our data is deserialized onto the User object, but before it's saved. In our tutorial about API platform 2, we used a Doctrine listener for this, which would still work. Though, it does some negatives…

6:55
Data Fixtures

…random controller like QuestionController, we can install a bundle to do it properly. Find your terminal and run: composer require orm-fixtures --dev This is another flex alias: orm-fixtures installs doctrine/doctrine-fixtures-bundle When this finishes... it installed a recipe! I committed all…

5:18
Clean URLs with Sluggable

…it does! It adds slug including a UNIQUE INDEX for slug. And when we run it with symfony console doctrine:migrations:migrate it explodes... for the same reason as last time: Not null violation. We're adding a new slug column to our table that…

6:48
Pagination

…re only using this method right here at the moment, so rename it to createOrderedByVotesQueryBuilder()... and this will now return a QueryBuilder - the one from Doctrine ORM. I'll remove the PHP documentation on top... and the only thing we need to do down here…

9:19
AMQP Priority Exchange

…in different "queues". Then we can instruct our worker to first read all messages from whatever queue async_priority_high is bound to before reading messages from whatever queue the async transport is bound to. This did work before with Doctrine, thanks to this queue…

7:15
The ManyToOne Relation

…want to do is relate an Answer to a Question. To do this... well... forget about Doctrine for a second. Let's just think about how this would look in a database. So: each answer belongs to a single question. We would normally model this…

8:35
Foundry: Fixture Model Factories

…we deserve better! Let's use a super fun new library instead. Google for "Zenstruck Foundry" and find its GitHub Page. Foundry is all about creating Doctrine entity objects in an easy, repeatable way. It's perfect for fixtures as well as for functional tests…

5:56
How Entity Controller Arguments Work

…is that code? At first, you might think this is another argument value resolver. But, there's nothing in that list that mentions "doctrine" or "entity". In reality, this is working via a different system. If we refresh now, the page still works. But if…

4:54
Extending with Events

…it says "Updated By", "Null". Our goal is to set that field automatically when a question is updated. A great solution for this would be to use the doctrine extensions library and its "blameable" feature. Then, no matter where this entity is updated - inside the…

8:03
Rendering Answer Data & Saving Votes

…templates/question/show.html.twig. If you scroll down a bit - here it is - we loop over the answers variable. That will still work: the Doctrine collection is something that we can loop over. But the answer variable will now be an Answer object. So…

6:02
Request Object & POST Data

…read the direction value and increase or decrease the vote count. We could do this with an AJAX call instead of a form submit. From a Doctrine and Symfony perspective, it really makes no difference. So I'll keep it simple and leave JavaScript out…

8:08
Simpler Validator for Checking State Change

…last tutorial, we put this above that same $dragonTreasures property, but inside the User entity. The validator would loop over each DragonTreasure, use Doctrine's UnitOfWork to get the $originalOwnerId, and then check to see if the $newOwnerId is different from the original. If it…

7:23
DTO -> Entity State Processor

…the item of type UserApi. We already talked about what's happening: the JSON is deserialized into a UserApi object. Good! Then the core Doctrine PersistProcessor is called because that's the default processor when using stateOptions. But... because our UserApi isn't an entity…

7:39
Joining Across a Relationship & The N + 1 Problem

…text. The moment we do that, Doctrine makes a second query from the question table to get that answer's question data: so in this case WHERE id = 463. Then we render the second answer... and make another query to get its question data..…

6:30