29 lines
712 B
PHP
29 lines
712 B
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Product;
|
|
use App\Models\ProductComment;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class ProductCommentSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$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;
|
|
});
|
|
}
|
|
}
|