File: D:/HostingSpaces/SBogers10/beat-the-barn.komma.nl/database/seeds/TestimonialSeeder.php
<?php
use Komma\KMS\Globalization\Languages\Models\Language;
use App\Testimonials\Models\Testimonial;
use App\Testimonials\Models\TestimonialTranslation;
use Illuminate\Database\Seeder;
use Illuminate\Support\Collection;
class TestimonialSeeder extends Seeder
{
/** @var \Faker\Generator */
protected $faker;
/** @var Collection */
protected $languages;
/**
* Run the seed
*/
public function run()
{
//Create a faker to generate fake data.
$this->faker = Faker\Factory::create();
//Get the languages
$this->languages = Language::whereIn('iso_2', config('seeds.languages'))->get(['id', 'iso_2']);
for($index = 0; $index < config('seeds.models.testimonials'); $index++) {
$this->createTestimonial();
}
}
/**
* @return Testimonial
*/
private function createTestimonial(): Testimonial
{
//Create the service itself...
$testimonial = new Testimonial([
'active' => 1,
'name' => $this->faker->words(rand(3, 5), true),
]);
$testimonial->save();
foreach ($this->languages as $language) {
$faker = Faker\Factory::create(strtolower($language->iso_2) . '_' . strtoupper($language->iso_2));
$projectTranslation = new TestimonialTranslation([
'title' => $faker->words(rand(3, 5), true),
'subtitle' => $faker->jobTitle.' - '.$faker->company,
'quote' => $faker->sentence(10),
]);
$projectTranslation->language()->associate($language);
$projectTranslation->translatable()->associate($testimonial);
$projectTranslation->save();
}
return $testimonial;
}
}