/** * Run the database seeds. * * @return void */ public function run() { // Increase memory for this bit ini_set('memory_limit', '256M'); // Set input file $input = storage_path('seeds/content_dump.json'); // Retrieve the raw response from JSON file $raw = file_get_contents($input); // Encode the JSON response into a PHP object $entries = json_decode($raw); foreach ($entries as $entry) { // Get the right letter object for relationship $letter = Letter::get()->where('letter', $entry->header->letter)->first(); // Array to hold new App\Definitnion for saveMany $new_definitions = []; // Build the Lemma object, save as $lemma print_r("- LEMMA -\n- "); $lemma = $this->makeLemma($entry, $letter); // Build the Definition objects foreach ($entry->definitions as $definition) { // Make the new App\Definition; Returns new App\Definitnion print_r(">"); $def = $this->makeDefinition($definition, $lemma); // Add new $def to the $new_definitions Array $new_definitions[] = $def; } // Save the new App\Lemma to the associated App\Letter $letter->lemmas()->save($lemma); print_r("\n- LEMMA SAVED -\n"); // Bulk-assign the App\Definition Array to the associated App\Lemma print_r("- BATCH SAVING DEFINITIONS ... "); $lemma->definitions()->saveMany($new_definitions); print_r("DONE\n"); } }
/** * Run the database seeds. * * @return void */ public function run() { $input = storage_path('seeds/roots.json'); $raw = file_get_contents($input); $roots = json_decode($raw); foreach ($roots->roots as $letter_key => $root_array) { // Get the proper App\Letter for this relationship $letter = Letter::get()->where("name", $letter_key)->first(); // Create a new array to store newly created roots $new_roots = []; // Create a new App\Root for each object in the Array foreach ($root_array as $root) { // Instantiate a new Root $new = new Root(); // Assign properties $new->display = $root; // Add the new App\Root to the $new_root Array $new_roots[] = $new; } // Save the new roots to the App\Letter print_r("Batch Saving {$letter->name} ... "); $letter->roots()->saveMany($new_roots); print_r("completed\n"); } }