d2d.emegrendeles.hu/database/seeders/PriceListSeeder.php
E98Developer 68b7c35bef git init
2026-02-28 06:53:05 +01:00

58 lines
1.8 KiB
PHP

<?php
namespace Database\Seeders;
use App\Enums\DbStatusFieldEnum;
use App\Models\PriceList;
use App\Models\Product;
use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Artisan;
class PriceListSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$priceList = new PriceList;
$priceList->supplier_id = \App\Models\Supplier::where('hooreycaId', 'S740')->get()->first()->id;
$priceList->status = DbStatusFieldEnum::active;
$priceList->available = '2021-11-01';
$priceList->save();
Artisan::call('db:seed', [
'--class' => 'PriceListPriceSeeder',
]);
return;
$priceList = new PriceList;
$priceList->supplier_id = \App\Models\Supplier::find(7)->id;
$priceList->status = DbStatusFieldEnum::active;
$priceList->available = '2021-11-01';
$priceList->save();
$products = Product::inRandomOrder()->take(rand(10, 35))->pluck('id');
foreach ($products as $product) {
$priceList->products()->attach($product, ['price' => rand(10, 999)]);
}
$priceList->save();
$priceList = new PriceList;
$priceList->supplier_id = \App\Models\Supplier::find(7)->id;
$priceList->status = DbStatusFieldEnum::active;
$priceList->available = Carbon::yesterday();
$priceList->save();
$products = Product::where('product_group_id', 50)->inRandomOrder()->take(rand(10, 35))->pluck('id');
$this->command->info('creating '.count($products).' price to 50 groupId product ');
foreach ($products as $product) {
$priceList->products()->attach($product, ['price' => rand(10, 999)]);
}
$priceList->save();
/*
*/
}
}