[ Part 4 ]- Populating database

Symfony 3 Jobeet tutorial - In this part we will create console command to populate our database with some fake data

Posted by Lukasz D. Tulikowski on February 4, 2017

Table of content

Follow me on Twitter

The Initial Data

To put some initial data in out database, we will create console command which allows us to populate a database. But before we do it, we will need some additional component called Faker. To install this component, we will need Composer.

To download composer go to your main project folder and run those commands as below

Once you download composer, you can install Symfony bundles, which are packages providing additional functionality to your application. We need bundle called Faker and to download these requirements execute command

$phpcomposer.pharrequirefzaninotto/faker

Now create new command directory in your bundle folder. Command which populate our database looks like that

You will see in details how to use it. Let’s create then five categories and ten jobs in each category.

$ bin/consoledb:init-c5-j10

That’s it. Some dummy data has already populated our database! But you still don’t see it anywhere, in case you check MySQL database itself. So it’s time to display what we have in out database generating some views and controllers, but this will be next part of the tutorial.