public function testAlwaysArray() { $item = 'foo'; $array = always_array($item); $this->assertTrue(is_array($array)); $this->assertArrayHasKey(0, $array); $this->assertArrayNotHasKey(1, $array); $item = ['foo']; $array = always_array($item); $this->assertArrayHasKey(0, $array); $this->assertArrayNotHasKey(1, $array); }
public function run() { $faker = Faker\Factory::create(); //Create random categories $categories = []; foreach (range(1, 5) as $number) { $categories[] = factory(\App\Models\Category::class)->create(['name' => $faker->word, 'description' => $faker->text(200)]); } //Create random products foreach (range(1, 140) as $number) { $newProduct = factory(\App\Models\Product::class)->create(['name' => $faker->word, 'price' => $faker->randomNumber(3), 'description' => $faker->text(200)]); //Append product to random category $randCategoryKeys = always_array(array_rand($categories, rand(1, 3))); foreach ($randCategoryKeys as $randCategoryKey) { $categories[$randCategoryKey]->products()->save($newProduct); } } }