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/werkenbijanvil.komma.nl/database/seeds/ContactServicepointSeeder.php
<?php

use Komma\KMS\Globalization\Languages\Models\Language;
use App\Servicepoints\Models\Servicepoint;
use App\Servicepoints\Models\ServicepointTranslation;
use Illuminate\Database\Seeder;
use Illuminate\Support\Collection;

class ContactServicepointSeeder extends Seeder
{
    /**
     * Run the seed
     */
    public function run()
    {
        //Get the languages
        $languages = Language::whereIn('iso_2', ['nl', 'en'])->get(['id', 'iso_2']);

        //Create the root page
        $foodTruckNewsPost      = $this->createChefSlagerContactServicePoint($languages);
    }

    /**
     * @param Collection $languages
     * @return Servicepoint
     */
    private function createChefSlagerContactServicePoint(Collection $languages): Servicepoint
    {
        //Create the service itself...
        $contactServicePoint = new Servicepoint([
            'name'        => 'Chef Slager',
            'active'      => 1,
        ]);

        $contactServicePoint->save();

        //...the Dutch translation
        $language = $languages->where('id', '104')->first();
        $servicePointTranslation = new ServicepointTranslation([
            'first_name'          => 'Chef',
            'last_name'           => 'Slager',
            'function'            => 'Dr. Butcher',
            'telephone_label'     => '+31 (0)6 12 34 56 78',
            'telephone_url'       => '+31612345678',
            'email'               => 'chef@demo-butcher.nl',
        ]);

        $servicePointTranslation->language()->associate($language);
        $servicePointTranslation->translatable()->associate($contactServicePoint);
        $servicePointTranslation->save();

        return $contactServicePoint;
    }
}