Files
einundzwanzig-portal/app/Http/Livewire/Frontend/Header.php
Shift 5776b01d15 Apply Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-12 coding style as a base with some minor additions.

You may customize the code style applied by configuring [Pint](https://laravel.com/docs/pint), [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer), or [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for your project root.

For more information on customizing the code style applied by Shift, [watch this short video](https://laravelshift.com/videos/shift-code-style).
2023-02-19 18:05:16 +01:00

79 lines
2.2 KiB
PHP

<?php
namespace App\Http\Livewire\Frontend;
use App\Models\City;
use App\Models\Country;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Route;
use Livewire\Component;
class Header extends Component
{
public ?Country $country = null;
public $currentRouteName;
public string $c = 'de';
public string $l = 'de';
public $bgColor = 'bg-21gray';
protected $queryString = ['l'];
public function rules()
{
return [
'c' => 'required',
'l' => 'required',
];
}
public function mount()
{
$this->l = Cookie::get('lang') ?: config('app.locale');
if (! $this->country) {
$this->country = Country::query()
->where('code', $this->c)
->first();
}
$this->currentRouteName = Route::currentRouteName();
$this->c = $this->country->code;
}
public function updatedC($value)
{
return to_route($this->currentRouteName, ['country' => $value, 'lang' => $this->l]);
}
public function updatedL($value)
{
Cookie::queue('lang', $this->l, 60 * 24 * 365);
return to_route($this->currentRouteName, ['country' => $this->c, 'l' => $value]);
}
public function render()
{
Cookie::queue('lang', $this->l, 60 * 24 * 365);
return view('livewire.frontend.header', [
'cities' => City::query()
->select(['latitude', 'longitude'])
->get(),
'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;
}),
]);
}
}