File: D:/HostingSpaces/SBogers10/reiskick.komma.nl/database/seeds/DefaultSiteDevelopmentPageSeeder.php
<?php
use Komma\KMS\Globalization\Languages\Models\Language;
use App\Vacancies\Models\VacancyTranslation;
use App\Pages\Models\Page;
use App\Pages\Models\PageTranslation;
use App\Routes\RouteService;
use App\Site\Site;
use Komma\KMS\Sites\SiteServiceInterface;
use Illuminate\Database\Seeder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
class DefaultSiteDevelopmentPageSeeder extends Seeder
{
/** @var RouteService */
private $routeService;
/** @var Site */
private $site;
/** @var Language */
private $languages;
/** @var Page */
private $siteRootPage;
private array $dataset = [
[
'attributes' => ['active' => 1, 'code_name' => 'home',],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => ['slug' => 'home', 'name' => 'home', 'meta_title' => 'home'],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => ['slug' => 'home', 'name' => 'home', 'meta_title' => 'home'],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'about'],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => ['slug' => 'over-ons', 'name' => 'Over ons', 'meta_title' => 'Over ons | Komma'],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => ['slug' => 'about-us', 'name' => 'About us', 'meta_title' => 'About | Komma'],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'services'],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => ['slug' => 'diensten', 'name' => 'Diensten', 'meta_title' => 'Diensten | Komma'],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => ['slug' => 'services', 'name' => 'Services', 'meta_title' => 'Services | Komma'],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'projects', 'has_wildcard' => true],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => [
'slug' => 'projecten', 'name' => 'Projecten',
'meta_title' => 'Projecten | Komma',
],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => ['slug' => 'projects', 'name' => 'Projects', 'meta_title' => 'Projects | Komma'],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'posts', 'has_wildcard' => true],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => ['slug' => 'nieuws', 'name' => 'Nieuws', 'meta_title' => 'Nieuws | Komma',],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => ['slug' => 'news', 'name' => 'Projects', 'meta_title' => 'News | Komma'],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'references'],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => [
'slug' => 'referenties', 'name' => 'Referenties',
'meta_title' => 'Referenties | Komma',
],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => ['slug' => 'testimonials', 'name' => 'Testimonials'],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'contact'],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => ['slug' => 'contact', 'name' => 'Contact', 'meta_title' => 'Contact | Komma'],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => ['slug' => 'contact', 'name' => 'Contact', 'meta_title' => 'Contact | Komma'],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'legal'],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => [
'slug' => 'algemene-voorwaarden', 'name' => 'Algemene voorwaarden',
'meta_title' => 'Algemene voorwaarden | Komma',
],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => ['slug' => 'terms-and-conditions', 'name' => 'Terms and conditions',],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'privacy'],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => [
'slug' => 'privacyverklaring', 'name' => 'Privacyverklaring',
'meta_title' => 'Privacyverklaring | Komma',
],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => [
'slug' => 'privacy-statement', 'name' => 'Privacy statement',
'meta_title' => 'Privacy statement | Komma',
],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'disclaimer'],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => [
'slug' => 'disclaimer', 'name' => 'Disclaimer',
'meta_title' => 'Disclaimer | Komma',
],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => [
'slug' => 'disclaimer', 'name' => 'Disclaimer',
'meta_title' => 'Disclaimer | Komma',
],
],
],
],
[
'attributes' => ['active' => 1, 'code_name' => 'vacancies', 'has_wildcard' => true],
'translations' => [
[
'language' => 'nl', //ISO-639-1 formatted
'attributes' => [
'slug' => 'Vacatures',
'name' => 'Vacatures',
'description' => 'Onze vacatures',
],
],
[
'language' => 'en', //ISO-639-1 formatted
'attributes' => [
'slug' => 'Vacancies',
'name' => 'Vacancies',
'description' => 'Our vacancies',
],
],
],
],
];
/**
* Run the seed
*/
public function run()
{
$this->routeService = new RouteService();
$this->site = Site::where('slug', '=', 'default')->first();
$this->languages = Language::whereIn('iso_2', config('seeds.languages'))->get(['id', 'iso_2']);
$this->siteRootPage = new Page(['active' => '0', 'site_id' => $this->site->id]);
$this->siteRootPage->makeRoot();
foreach ($this->dataset as $pageData) {
//Only seed the page if it's code is defined in seeds.pages
if (in_array($pageData['attributes']['code_name'], config('seeds.pages'), true)) {
$this->createPage($pageData);
}
}
}
/**
* @param array $pageData
*
* @return Page
*/
private function createPage(array $pageData): Page
{
//Create the page itself...
$page = new Page($pageData['attributes']);
$page->site()->associate($this->site);
$page->makeLastChildOf($this->siteRootPage);
$page->save();
foreach ($pageData['translations'] as $translationData) {
$language = $this->languages->firstWhere('iso_2', $translationData['language']);
if ($language) {
$pageTranslation = new PageTranslation($translationData['attributes']);
$pageTranslation->language()->associate($language);
$pageTranslation->translatable()->associate($page);
$pageTranslation->save();
}
}
$this->routeService->createOrUpdateRoutesForModelsTranslationsIfChanged($page);
return $page;
}
}