512 search results

Setting Relations in Foundry

…want a lot more. This is a job perfectly suited for our good friend: Foundry. Remove the manual code, then anywhere, say: StarshipPartFactory::createMany(100): And try the fixtures: symfony console doctrine:fixtures:load Uh-oh! starship_id cannot be null in starship_part. This…

4:24
Transport: Do Work Later (Async)

…ImagePost - from the logic that actually does that work. And... it's a nice coding pattern: it's easy to test and if we need to add Ponka to an image from anywhere else in our system, it will be super pleasant. But this pattern…

7:33
Many To Many with Foundry

…createMany(100). Below, set droids to DroidFactory::randomRange(1, 5): This will assign anywhere between 1 and 5 random droids to each Starship. Maybe you noticed something: we're setting a droids property here, but in Starship, we do not have a setDroids() method! Normally…

2:52
The REST API Tutorial

…easy stuff. Nope, we’ll attack the ugliest areas of an API, like custom methods and where each piece of documentation should live and why. The Project: Resources and Links¶ The project? Introducing Code Battles: a super-serious site where programmers battle against projects. After…

3:07
Embedding Custom DTO's

…as a custom array of embedded data? Check it out. In the src/ApiResource/ directory, though this class could live anywhere, create a new class called DailyQuestTreasure. This will represent the treasure that you could win by completing a DailyQuest. Inside, create a public function _…

4:47
Our First Test

…tests! Mmmm... where do we put this new test? We can technically put our tests anywhere within our project. But when we installed symfony/test-pack, Flex created a tests/ directory which, no surprise, is the recommended place to put our tests. Remember that, in…

7:16
Assets: Custom CSS and JS

…each individual CRUD controller. So we can control assets on a global level or for just one section. Let's make our change globally so that we can change the color of the sidebar on every page. Anywhere inside of DashboardController, go back to the…

8:17
Dispatching a Message inside a Handler?

…handled by our command bus: we have a DeleteImagePost command and DeleteImagePostHandler. But inside config/packages/messenger.yaml, we're not routing this class anywhere, which means it's being handled immediately. Oh, and notice: we're still passing the entire entity object into the…

5:30
Access Token Authenticator

…perfect system just for this! Spin over and open up config/packages/security.yaml. Anywhere under your firewall add access_token: This activates a listener that will watch every request to see if it has an Authorization header. If it does, it will read that…

8:56
Reusing Queries in the Query Builder

…super-duper if we could reuse that logic instead of repeating it over and over again. Let's do that! Anywhere inside here, add a new private function called addFortuneCookieJoinAndSelect(). This will accept a QueryBuilder object (make sure you get the one from Doctrine\ORM…

4:42
Builder in Symfony & with a Factory

…Then, pass that manually into the builder as $this->logger: We're seeing some of the benefits of the factory pattern here. Since we've already centralized the instantiation of CharacterBuilder, anywhere that needs a CharacterBuilder, like GameApplication, doesn't need to change at all..…

8:18
Attachments and Images

…you'll see a terms-of-service.pdf file. Move this into assets/, though it could live anywhere. In TripController::show(), we need to get the path to this file. Add a new string $termsPath argument and with the #[Autowire] attribute and %kernel.project_dir…

3:49
make:user

…email property. I wanted you to see this change... but the user provider isn't important yet. I'll show you exactly how and where it's used as we go along. Next: we have total control over how our User class looks. The power…

5:57
Toast Notifications

…right that disappear automatically with CSS transitions and can tie my shoes for me. On our CRUD controllers, I'm already setting a success flash message... but I'm not rendering it anywhere. In the templates/ directory, create a new _flashes.html.twig. To start…

3:46
Ajax-Powered HTML Updates & a CSS Transition

…item element also has a removing class, change the opacity to zero. Thanks to the transition, that change will happen gradually. And where does this removing class come from? Good question! We are going to add it. Back in the controller, right at the beginning…

5:13
index.php to HttpKernel::handle()

…a try catch! That's not important yet. But later, we'll see what happens when an exception is thrown from anywhere. The real logic of HttpKernel lives in this handleRaw() method. Scroll down a little to find it. Ah yes: handleRaw(). This is the…

6:50
Allow Admin Users to Edit any Treasure

…we can add a shortcut to Foundry. Open UserFactory. We're going to create something called a "state" method. Anywhere inside, add a public function called, how about withRoles() that has an array $roles argument and returns self, which will make this more convenient when…

4:11
Dependency Injection

…That's true. But, you can't just grab them out of thin air from anywhere in your code. For example, there's no Cache::get() static method that you can call whenever you want that will return the $cache service object. Nothing like that…

9:34
Verifying the Signed Confirm Email URL

…config/services.yaml, we set up a global "bind" that said: Whenever an autowired service has an argument named $formLoginAuthenticator, please pass this service. One of the cool things about bind is that if there is no matching argument anywhere in our app, it throws…

7:18
Processing Streams by Hand for Fun & Profit

…then the HTML is passed to the Turbo Stream system... and it works its magic. But in theory, you could grab some Turbo Stream HTML from anywhere and tell the Stream system to process it. And... it's kind of fun! Head to the homepage…

5:18