1000 search results

Relations in Foundry

…Notice that, in getDefaults(), we are not setting the question property. And so, if you spin over to your terminal and run: symfony console doctrine:fixtures:load ... we get our favorite error: question_id column cannot be null. To fix this, in AppFixtures, pass a…

4:41
UUID as a API Identifier

…talked about it before. Go to the top of User. Every API Resource needs an identifier. And when you use Doctrine, API Platform assumes that you want the database id as the identifier. To tell it to use something different, add @ApiProperty() with identifier=false: That…

5:16
UUID's

…how do we generate these UUID strings? Symfony 5.2 will come with a new UUID component, which should allow us to easily generate UUID's and store them in Doctrine. But since that hasn't been released yet, we can use ramsey/uuid, which…

7:29
Type Validation

…its work, it first tries to figure out what type the field should be, which we know it does in a number of different ways, like reading Doctrine metadata, setter argument type-hints and even PHPDoc. Then, for scalar types like the int price, if…

7:29
Input Data Transformer

…object. Second, we transform that CheeseListingInput into a CheeseListing in the data transformer. And third, the normal Doctrine data persister saves things. That's a really clean process! Go back to the docs and look at the put operation that updates cheeses. Will this work…

4:24
Output Properties & Metadata

…that's no surprise! When we serialize a CheeseListing entity, API Platform can use the Doctrine metadata above the title property to figure out that it's a string: But in this case, when it looks at title, it doesn't get any info about…

7:14
Custom Filter for Custom Resources

…had before: The only difference is that the apply() method has different arguments than filterProperty()... which makes sense because that method was all about querying via Doctrine. Before we start filling this in, go to src/Entity/DailyStats.php so we can use the filter…

7:49
Custom Filter, getDescription() & properties

…implement an interface or extend some base class. In this case, we need to extend AbstractFilter. Make sure you get the one from Doctrine ORM... it's actually impossible to see which one we have here... so I'll randomly guess: Hey! I got it…

7:09
Collection "Types" and readableLink

…lot of metadata about each property, like its type and whether it's required. And it gets that from many different sources like Doctrine metadata and our own PHPDoc. And because collecting all of this can take time, it caches it. Now, API Platform is…

7:12
Property Metadata

… Integers? Aliens? API Platform gets metadata about each property from many different places, like by reading Doctrine metadata, PHPDoc, looking at the return types of getter methods, looking at the argument type-hint on setters, PHP 7.4 property types and more. What's really…

6:20
Custom Resource Data Provider

…as the identifier? In Doctrine, it happens automatically thanks to the @ORM\Id annotation: When you're not in an entity - or if you want to use a field other than the database id in an entity - you can add @ApiProperty() with identifier=true: Cool! Let…

6:40
Adding & Populating the Custom Field

…find the original tab and refresh. Oh! It's not an array of users! It's a Paginator object with a Doctrine Paginator inside! So... this obviously isn't an array, but the Paginator object is iterable: we can loop over it like an array…

5:10
Custom Item Data Provider

…it extends a less strict ItemDataProviderInterface. I'm implementing that other crazy interface because that's what the core Doctrine item data provider uses... and I want to be able to pass it the same arguments. Ok: go to the "Code"->"Generate" menu - or…

6:57
Completely Custom Field via a Data Provider

…providers that load one object for the item operations. Normally, we don't need to think about this system because API Platform has a built-in Doctrine data provider that handles all of it for us. But if we want to load some extra data…

9:19
App & Test Setup

…who can publish an item under different conditions. Then we'll do everything custom: add completely custom fields, completely custom API resources that aren't backed by Doctrine, custom filters and we'll even dive deep into API Platform's input and output DTO system…

7:44
Processing Encore Files through inline_css()

…EntrypointLookupInterface - we're using a "service subscriber". You can learn about this in, oddly-enough, our tutorial about Symfony & Doctrine. To fetch the service, go down to getSubscribedServices() and add EntrypointLookupInterface::class. Back up in getEncoreEntryCssSource(), we can say $files = $this->container->get(EntrypointLookupInterface…

7:27
Async Emails with Messenger

…email - you need to configure a "queueing" system where details about that work - called "messages" - will be sent. Messenger calls these transports. Because we're already using Doctrine, the easiest "queueing" system is a database table. Uncomment that MESSENGER_TRANSPORT_DSN to use it. Next…

6:11
Unit Testing our Emails

…a general rule, I like to mock services but manually instantiate simple "data" objects, like Doctrine entities. The reason is that these classes don't have dependencies and it's usually dead-simple to put whatever data you need on them. Basically, it's easier…

7:56
Lets Generate a PDF!

…or 0 users. If it doesn't send any emails, try reloading your fixtures by running: php bin/console doctrine:fixtures:load If you are so lucky that it's sending more than 2 emails, you'll get an error from Mailtrap, because it limits…

4:56
Using a Base Email Template

…data is fresh... with recent article created dates. Run: php bin/console doctrine:fixtures:load This should add enough users and articles that about 1-2 authors will be subscribed to the newsletter and have recent articles. Try that command: Ha! It didn't explode…

8:54