ldc-startcoq/database/seeders/ProductCommentSeeder.php

30 lines
712 B
PHP
Raw Permalink Normal View History

2023-02-23 16:23:00 +01:00
<?php
namespace Database\Seeders;
2023-06-21 10:24:56 +00:00
use App\Models\Product;
2023-02-23 16:23:00 +01:00
use App\Models\ProductComment;
use Illuminate\Database\Seeder;
class ProductCommentSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
2023-06-21 10:24:56 +00:00
$jj = 1;
Product::each(function (Product $product) use (&$jj) {
if ($product->is_tasted) {
ProductComment::factory(1)->make()->each(function (ProductComment $productcomment) use ($product) {
$productcomment->product_id = $product->id;
$productcomment->saveOrFail();
});
}
$jj = $jj + 1;
});
2023-02-23 16:23:00 +01:00
}
}