HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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;
    }
}