ldc-volena/database/seeders/TestimonialSeeder.php
2023-11-16 09:42:21 +01:00

33 lines
957 B
PHP

<?php
namespace Database\Seeders;
use App\Enums\Testimonials\TypeEnum;
use App\Lib\Helpers\FileStorageHelper;
use App\Models\Testimonial;
use Illuminate\Database\Seeder;
class TestimonialSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
FileStorageHelper::removeModelFiles(new Testimonial());
foreach (TypeEnum::cases() as $type) {
Testimonial::factory(3)->make()->each(function (Testimonial $testimonial) use ($type) {
$testimonial->type = $type->value;
$testimonial->picture = FileStorageHelper::storeFile(
new Testimonial(),
new \SplFileInfo(\resource_path(
'../database/factories/assets/testimonials/default-picture-100x100.png'
))
);
$testimonial->save();
});
}
}
}