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
}
}
3 Comments
Hi,
Unfortunately there's no code block :/
[Edit] You can use the following (taken from finished project code):
declare(strict_types=1); namespace App\Factory; use App\Entity\User; use App\Repository\UserRepository; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Zenstruck\Foundry\ModelFactory; use Zenstruck\Foundry\Proxy; use Zenstruck\Foundry\RepositoryProxy; /** * @extends ModelFactory<User> * * @method User|Proxy create(array|callable $attributes = []) * @method static User|Proxy createOne(array $attributes = []) * @method static User|Proxy find(object|array|mixed $criteria) * @method static User|Proxy findOrCreate(array $attributes) * @method static User|Proxy first(string $sortedField = 'id') * @method static User|Proxy last(string $sortedField = 'id') * @method static User|Proxy random(array $attributes = []) * @method static User|Proxy randomOrCreate(array $attributes = []) * @method static UserRepository|RepositoryProxy repository() * @method static User[]|Proxy[] all() * @method static User[]|Proxy[] createMany(int $number, array|callable $attributes = []) * @method static User[]|Proxy[] createSequence(array|callable $sequence) * @method static User[]|Proxy[] findBy(array $attributes) * @method static User[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) * @method static User[]|Proxy[] randomSet(int $number, array $attributes = []) */ final class UserFactory extends ModelFactory { const USERNAMES = [ 'FlamingInferno', 'ScaleSorcerer', 'TheDragonWithBadBreath', 'BurnedOut', 'ForgotMyOwnName', 'ClumsyClaws', 'HoarderOfUselessTrinkets', ]; public function __construct( private readonly UserPasswordHasherInterface $passwordHasher, ) { parent::__construct(); } protected function getDefaults(): array { return [ 'email' => self::faker()->email(), 'password' => 'password', 'username' => self::faker()->randomElement(self::USERNAMES) . self::faker()->randomNumber(3), ]; } protected function initialize(): self { return $this ->afterInstantiate(function(User $user): void { $user->setPassword($this->passwordHasher->hashPassword( $user, $user->getPassword() )); }) ; } protected static function getClass(): string { return User::class; } }Hey Jmsche,
Code blocks are available for this chapter now! Thank you for your patience :)
Cheers!
Hey Jmsche,
We're sorry for the delay, we're working on adding more code blocks to the recently published chapters and will add them shortly. For now, thanks for sharing it in the comments with others :)
Cheers!
"Houston: no signs of life"
Start the conversation!