Files
einundzwanzig-portal/app/Http/Livewire/Frontend/Welcome.php
HolgerHatGarKeineNode 726e6f18d7 fixes #7
2023-06-01 13:23:14 +02:00

77 lines
2.2 KiB
PHP

<?php
namespace App\Http\Livewire\Frontend;
use App\Models\Country;
use Illuminate\Support\Facades\Cookie;
use Livewire\Component;
use RalphJSmit\Laravel\SEO\Support\SEOData;
class Welcome extends Component
{
public string $c = 'de';
public string $l = 'de';
protected $queryString = ['c', 'l'];
public function rules()
{
return [
'c' => 'required',
'l' => 'required',
];
}
public function mount()
{
$this->l = Cookie::get('lang') ?: config('app.locale');
$this->c = Cookie::get('country') ?: config('app.country');
Cookie::queue('lang', $this->l, 60 * 24 * 365);
Cookie::queue('country', $this->c, 60 * 24 * 365);
}
public function updated($property, $value)
{
$this->validate();
if ($property === 'c') {
$c = $value;
} else {
$c = $this->c;
}
if ($property === 'l') {
$l = $value;
} else {
$l = $this->l;
}
Cookie::queue('lang', $this->l, 60 * 24 * 365);
Cookie::queue('country', $this->c, 60 * 24 * 365);
return to_route('welcome', ['c' => $c, 'l' => $l]);
}
public function render()
{
return view('livewire.frontend.welcome', [
'countries' => Country::query()
->select('id', 'name', 'code')
->orderBy('name')
->get()
->map(function (Country $country) {
$country->name = config('countries.emoji_flags')[str($country->code)
->upper()
->toString()].' '.$country->name;
return $country;
}),
])->layout('layouts.guest', [
'SEOData' => new SEOData(
title: __('Welcome'),
description: __('Welcome to the portal of the Einundzwanzig Community.'),
image: url()->route('imgPublic', ['path' => 'img/screenshot.png', 'h' => 630, 'w' => 1200, 'fit' => 'crop'])
),
]);
}
}