36 lines
922 B
PHP
36 lines
922 B
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Product;
|
|
use App\Models\Recipe;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class RecipeSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
Recipe::factory(25)->create();
|
|
|
|
// Seeder for recipe_recipe table.
|
|
$recipe = Recipe::query()->get();
|
|
Recipe::each(function (Recipe $model) use ($recipe) {
|
|
$offset = rand(0, 9);
|
|
$length = rand(0, 3);
|
|
$model->recipes()->saveMany($recipe->slice($offset, $length));
|
|
});
|
|
|
|
// Seeder for recipe_products table.
|
|
$products = Product::query()->get();
|
|
Recipe::each(function (Recipe $model) use ($products) {
|
|
$offset = rand(0, 24);
|
|
$length = rand(1, 3);
|
|
$model->products()->saveMany($products->slice($offset, $length));
|
|
});
|
|
}
|
|
}
|