40 lines
1.4 KiB
PHP
40 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Database\Seeders;
|
||
|
|
|
||
|
|
use App\Lib\Helpers\FileStorageHelper;
|
||
|
|
use App\Models\Commitment;
|
||
|
|
use App\Models\Product;
|
||
|
|
use Illuminate\Database\Seeder;
|
||
|
|
|
||
|
|
class ProductSeeder extends Seeder
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Run the database seeds.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function run()
|
||
|
|
{
|
||
|
|
FileStorageHelper::removeModelFiles(new Product());
|
||
|
|
Product::factory(25)->make()->each(function (Product $product, int $key) {
|
||
|
|
$product->picture_thumbnail = FileStorageHelper::storeFile(new Product(), new \SplFileInfo(\resource_path(
|
||
|
|
'../database/factories/assets/products/default-picture-332x252.png'
|
||
|
|
)));
|
||
|
|
$product->picture_ambiance = FileStorageHelper::storeFile(new Product(), new \SplFileInfo(\resource_path(
|
||
|
|
'../database/factories/assets/products/default-picture-774x515.png'
|
||
|
|
)));
|
||
|
|
$product->picture_packshot = FileStorageHelper::storeFile(new Product(), new \SplFileInfo(\resource_path(
|
||
|
|
'../database/factories/assets/products/default-picture-327x252.png'
|
||
|
|
)));
|
||
|
|
$product->order = $key + 1;
|
||
|
|
$product->saveQuietly();
|
||
|
|
});
|
||
|
|
|
||
|
|
$commitments = Commitment::query()->get();
|
||
|
|
Product::query()->each(function (Product $product) use ($commitments) {
|
||
|
|
$product->commitments()->saveMany($commitments->random(\rand(0, 4)));
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|