예제 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     if ($this->command->confirm('Install default ingredient and recipe categories?')) {
         $ingredientCategories = explode("\n", file_get_contents(database_path('seeds/lists/ingredient-categories.csv')));
         foreach ($ingredientCategories as $ingredientCategory) {
             $term = Term::where([['vocabulary_id', '=', Vocabularies::INGREDIENT_CATEGORIES], ['name', '=', $ingredientCategory]])->first();
             if (!$term) {
                 Term::create(['vocabulary_id' => Vocabularies::INGREDIENT_CATEGORIES, 'name' => $ingredientCategory]);
             }
         }
     }
 }
예제 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     if ($this->command->confirm('Install default ingredients?')) {
         $ingredients = explode("\n", file_get_contents(database_path('seeds/lists/ingredients.csv')));
         $categories = Term::where('vocabulary_id', '=', \App\Data\Enums\Vocabularies::INGREDIENT_CATEGORIES)->lists('id', 'name')->toArray();
         foreach ($ingredients as $ingredientLine) {
             list($category, $name) = explode('|', $ingredientLine);
             if (!Ingredient::where('name', $name)->first()) {
                 $ingredient = Ingredient::create(['name' => $name]);
                 $category = data_get($categories, $category);
                 if ($category) {
                     $ingredient->categories()->attach($category);
                 }
             }
         }
     }
 }