1000 search results

Fixtures: Seeding Dummy Data!

…one article... but it should work! Try it: find your terminal and run a new console command: php bin/console doctrine:fixtures:load This will ask if you want to continue because - important note! - the command will empty the database first, and then load fresh…

9:34
Sluggable & other Wonderful Behaviors

…Now the recipe installs. Thanks to this, we now have a shiny new config/packages/stof_doctrine_extensions.yaml file: This is where we need to enable the extensions we want. We want sluggable. We can use the example in the docs as a guide…

7:24
Updating an Entity

…not needed for updates! When you query Doctrine for an object, it already knows that you want that object to be saved to the database when you call flush(). Doctrine is also smart enough to know that it should update the object, instead of inserting…

7:37
Using Faker for Seeding Data

…Faker function: $this->faker->numberBetween(5, 100): After these few improvements, let's make sure the system is actually as easy as pie. Find your terminal and run: php bin/console doctrine:fixtures:load No errors and... back on the browser, it works! Of course…

6:29
Fetching Relations

…s why we use 'article' => $article. Of course, behind the scenes, Doctrine will make a query where article_id = the id from this Article. But, in PHP, we think all about objects. As nice as this was... there is a much simpler way…

6:02
Awesome Random Fixtures

…fixed, let's rename the class back from this ridiculous name to CommentFixture: To celebrate, move over, refresh and... awesome! 8, random comments. We rock! Next, let's learn about some tricks to control how Doctrine fetches the comments for an article, like, their order.

4:30
OrderBy & fetch EXTRA_LAZY

… Move over and, refresh! Brilliant! The newest comments are on top. This actually changed how Doctrine queries for the related comments. Oh, and I want to mention two quick things about the syntax for annotations. First... well... the syntax can sometimes be confusing - where to…

6:23
Fixture References & Relating Objects

…for each loop. For the second argument, it passes the object itself. This reference system is a little "extra" built into Doctrine's fixtures library. When you add a "reference" from one fixture class, you can fetch it out in another class. It's super…

5:07
Partial Mocking

…going on? This is subtle: PhpUnit is smart enough to take this one dinosaur object and return it each time growFromSpecification() is called. But to Doctrine, it looks like we're asking it to save the same one Dinosaur object: not three separate dinosaurs. The…

3:59
Test Fixtures & Fast Databases!

…step will have already been done for you automatically. We haven't hooked the fixtures into our tests yet, but we can at least try them! Run: php bin/console doctrine:fixtures:load Go check out the browser! Yes! The fixtures gave us 3 enclosures…

7:18
Tests, Assertions & Coding

…tutorial/ directory with a Dinosaur class inside. Copy that and paste it into the real Entity directory. This is just a simple class with a length property. It does have Doctrine annotations, but that's not important! Sure, we will eventually be able to save…

6:40
Customizing the Forms

…production anyways, but, you've been warned! Move over to your terminal to generate the migration: php bin/console doctrine:migrations:diff That looks right! Run it: php bin/console doctrine:migrations:migrate New field added! Now, how can we add it to the form?…

6:27
My Users don't have a Username!

… No more username! Register as aquanaut4@gmail.com and submit. Check it out in the database: php bin/console doctrine:query:sql 'SELECT * FROM user' There it is! The username is now equal to the email. Oh, and if you're using the profile edit…

2:22
DQL Filtering & Sorting

…a lot of species. Start by adding a list key and a new, awe-inspiring option: dql_filter. For the value, pretend that you're building a query in Doctrine. So, entity.speciedCount >= 50000: The alias will always be entity. Try it! Ten down…

5:19
CollectionType Field

…about the owning and the inverse sides of the relationship, and things called orphanRemoval and cascading. There is some significant Doctrine magic going on behind the scenes to get it working. So in a few minutes, we're going to look at a more custom…

5:51
Webhooks: Preventing Replay Attacks

…the AppBundle/Entity directory, create a new PHP Class called StripeEventLog: Give it a few properties: $id, $stripeEventId and a $handledAt date field: Since this project uses Doctrine, I'll add a special use statement on top and then add some annotations, so that this…

5:41
Tracking Cancelations in our Database

…month: Cool! To deactivate the subscription in the controller, it's as easy as saying $subscription->deactivateSubscription() and then saving it to the database with the standard persist() and flush() Doctrine code: And that should do it! Let's give this guy a try. Go…

7:57
Webhook: Subscription Canceled

…be canceled. Below, really simple, say $subscription->cancel(). Then, use the Doctrine entity manager to save this to the database: Mind blown! Back in the controller, call this! Above the switch statement, add a $subscriptionHelper variable set to $this->get('subscription_helper'): Finally, call $subscriptionHelper…

5:08
Testing Part 2: Faking the Event Lookup

…that true is false on line 43 It looks like our webhook is not working, because the subscription is still active. But actually, that's not true: Doctrine is tricking us! In reality, the database has been updated to show that the Subscription is canceled…

5:06
Stripe Customers + Our Users

…getters and setters for the new property: Now that our PHP code is updated, we need to actually add the new column to our table. Since this project uses Doctrine migrations, open a new tab and run: All that did was create a new file…

2:55