I'm trying to seed the database through the model factory. It is no problem to fill the tables, but the data has to be one to many to one. So 1 project, has 1 or more sites, and these sites are on a server. I figured out how to make a relation with 1 to many but not how to use that same data for the many to one again. Here's my code:
$projects = factory('App\Project', 5)->create();
$servers = factory('App\Server', 5)->create();
$projects->each(function($project)
{factory('App\Site', 2)
->create(['project_id' => $project->id]);
});
So the question is how to add the sites to the server.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zRKrBR
via IFTTT
Aucun commentaire:
Enregistrer un commentaire