39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders\Development;
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use App\Models\Product;
|
|
use App\Models\Subrange;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class ProductSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$subranges = Subrange::query()->get();
|
|
$jj = 1;
|
|
// @phpstan-ignore-next-line
|
|
Product::factory(150)->make()->each(function (Product $product) use (&$jj, $subranges) {
|
|
$slider_pictures = [];
|
|
for ($i = 1; $i <= 5; $i++) {
|
|
$slider_pictures[] = FileStorageHelper::storeFile($product, new \SplFileInfo(\resource_path(
|
|
'../database/factories/assets/product/image-product-slide-0' . $i . '-396x286.jpg'
|
|
)));
|
|
}
|
|
$product->slider_pictures = $slider_pictures;
|
|
$product->sticker_sm = FileStorageHelper::storeFile($product, new \SplFileInfo(\resource_path(
|
|
'../database/factories/assets/product/sticker-sm-product-206x159.jpg'
|
|
)));
|
|
$product->order = $jj;
|
|
$product->subrange()->associate($subranges->random());
|
|
$product->saveOrFail();
|
|
$jj = $jj + 1;
|
|
});
|
|
}
|
|
}
|