Files
nuhodds_fi4/app/Livewire/TopMenuItems.php
T
2026-01-06 13:09:18 +01:00

92 lines
2.3 KiB
PHP

<?php
namespace App\Livewire;
use App\Models\Client;
use App\Models\Sport;
use App\Models\User;
use Illuminate\Support\Facades\Route;
use Livewire\Component;
class TopMenuItems extends Component
{
public $clients = [];
public ?string $client = '';
public $sports = [];
public $sport_id = 0;
public $sporticon = '';
public $iconcolor = '';
public $current = '';
protected $listeners = [
'reload_data_left' => '$refresh',
'reload_data_right' => '$refresh',
];
public function mount()
{
$cps = Client::where('id', auth()->user()->client_id)->pluck('sport')->first();
$this->sports = Sport::whereIn('id', $cps)->pluck('name', 'id');
$this->sporticon = Sport::where('id', auth()->user()->sport_id)->pluck('icon')->first();
$this->iconcolor = Sport::where('id', auth()->user()->sport_id)->pluck('color')->first();
$this->sport_id = auth()->user()->sport_id;
$this->clients = Client::pluck('name', 'id')->all();
$this->client = Client::where('id', auth()->user()->client_id)->pluck('name')->first();
$this->current = Route::currentRouteName();
}
public function render()
{
return view('livewire.top-menu-items');
}
public function swop($client_id)
{
$providers = Client::where('id', $client_id)->pluck('provider')->first();
$provider_id = array_shift($providers);
$bookmakers = Client::where('id', $client_id)->pluck('bookmaker')->first();
$bookmaker_id = array_shift($bookmakers);
User::where('id', auth()->user()->id)->update(['sport_id' => 1, 'provider_id' => $provider_id, 'bookmaker_id' => $bookmaker_id, 'client_id' => $client_id]);
$this->js('window.location.reload()');
}
public function swopBookmaker($bookmaker_id)
{
User::where('id', auth()->user()->id)->update(['bookmaker_id' => $bookmaker_id]);
$this->js('window.location.reload()');
}
public function swopProvider($provider_id)
{
User::where('id', auth()->user()->id)->update(['provider_id' => $provider_id]);
$this->dispatch('reload_data_right');
}
public function swopSport()
{
User::where('id', auth()->user()->id)->update(['sport_id' => $this->sport_id]);
$this->js('window.location.reload()');
}
}