Commit 0bb4d1da authored by Antoine Le Gonidec's avatar Antoine Le Gonidec

Add ability to group children in archives relationships seeder

parent 1950ee45
......@@ -314,14 +314,24 @@ class ArchivesRelationshipsSeeder extends Seeder {
*/
public function run() {
foreach ( $this->relationships as $relationship ) {
$required = isset($relationship['required']) ?
$relationship['required'] : true;
$parent = Archive::where('md5', $relationship['parent_md5'])
->first();
$child_id = Archive::where('md5', $relationship['child_md5'])
->pluck('id')
->first();
$parent->children()->attach($child_id, [ 'required' => $required ]);
if ( isset($relationship['children']) ) {
foreach ( $relationship['children'] as $child ) {
$required = $child['required'];
$child_id = Archive::where('md5', $child['md5'])
->pluck('id')
->first();
$parent->children()->attach($child_id, [ 'required' => $required ]);
}
} else {
$required = isset($relationship['required']) ?
$relationship['required'] : true;
$child_id = Archive::where('md5', $relationship['child_md5'])
->pluck('id')
->first();
$parent->children()->attach($child_id, [ 'required' => $required ]);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment