Build the Database with Eloquent, Faker and Flysystem

Posted by Unknown on Wednesday, August 27, 2014

In this part, we will create the structure of the database. We will create the tables using migrations and seed the database using seeders. Also, you will learn how to grab some random images from LoremPixel and put them on the filesystem using Flysystem. You’ll also be adding some randomly generated data using the Faker library.

Much like with part 1, you can download this part’s code from github.


Install the libraries


The installation is very straightforward with Composer.


Require these projects:



"fzaninotto/faker": "1.5.*@dev",
"league/flysystem": "dev-feature/eventable-filesystem",
"dropbox/dropbox-sdk": "dev-master"


Execute composer update and everything will be installed and updated smoothly.


Build the structure of the database


Until now, we had just one migration file. We need two more for our application. One table that will keep the data for photos and another for categories. To find out more about Artisan and Migrations, see this post.



php artisan migrate:make create_photos_table
php artisan migrate:make create_categories_table


These two commands create two migration files. Let’s start filling them with some schema. First, we start with the photos migration file. Stop for a moment and think what we need for this one. Earlier, we installed the flysystem library.


The flysystem library can handle files on different locations: the local filesystem, Dropbox, AWS3, Rackspace Cloud Files and more. We need it for the local filesystem on our development environment and we have to use Dropbox for production. Why is that? Heroku is a Paas (Platform as a Service) so we don’t have full control of the filesystem. There are only two directories that can be writable: ./temp and ./logs. You can write files only using git for deployment, and not in any other folder. Why don`t we just use those two directories? Because they are temporary. If something goes wrong and the Dyno restarts, all the files in those directories are deleted. It’s not safe to work with those two directories.


If you want to know more about flysystem read this article on sitepoint by Lukas White or their documentation .


Continue reading %Build the Database with Eloquent, Faker and Flysystem%




more

{ 0 comments... » Build the Database with Eloquent, Faker and Flysystem read them below or add one }

Post a Comment

Popular Posts