71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders\Development;
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use App\Models\Advice;
|
|
use App\Models\Product;
|
|
use App\Models\Tag;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class AdviceSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
// @phpstan-ignore-next-line
|
|
Advice::factory(50)->make()->each(function (Advice $advice) {
|
|
$advice->picture = FileStorageHelper::storeFile(
|
|
$advice,
|
|
new \SplFileInfo(\resource_path(
|
|
'../database/factories/assets/products/product_fake_650_690.jpg'
|
|
))
|
|
);
|
|
$advice->sticker = FileStorageHelper::storeFile(
|
|
$advice,
|
|
new \SplFileInfo(\resource_path(
|
|
'../database/factories/assets/products/product_fake_370_300.jpg'
|
|
))
|
|
);
|
|
$advice->sticker_sm = FileStorageHelper::storeFile(
|
|
$advice,
|
|
new \SplFileInfo(\resource_path(
|
|
'../database/factories/assets/products/product_fake_270_145.jpg'
|
|
))
|
|
);
|
|
$advice->saveOrFail();
|
|
});
|
|
|
|
$this->call([
|
|
TagSeeder::class
|
|
]);
|
|
|
|
// Seeder for taggable table.
|
|
$tags = Tag::query()->get();
|
|
Advice::each(function (Advice $model) use ($tags) {
|
|
$offset = rand(0, 9);
|
|
$length = rand(1, 2);
|
|
$model->tags()->saveMany($tags->slice($offset, $length));
|
|
});
|
|
|
|
// Seeder for advice_advice table.
|
|
$advice = Advice::query()->get();
|
|
Advice::each(function (Advice $model) use ($advice) {
|
|
$offset = rand(0, 9);
|
|
$length = rand(0, 3);
|
|
$model->advices()->saveMany($advice->slice($offset, $length));
|
|
});
|
|
|
|
// Seeder for advice_products table.
|
|
$products = Product::query()->get();
|
|
Advice::each(function (Advice $model) use ($products) {
|
|
$offset = rand(0, 24);
|
|
$length = rand(1, 3);
|
|
$model->products()->saveMany($products->slice($offset, $length));
|
|
});
|
|
}
|
|
}
|