127 lines
5.3 KiB
PHP
127 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Filament\Infolists\Components\RepeatableEntry;
|
|
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
|
|
use Filament\Infolists\Components\TextEntry;
|
|
use Filament\Schemas\Components\Tabs;
|
|
use Filament\Schemas\Components\Tabs\Tab;
|
|
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
|
use Filament\Schemas\Contracts\HasSchemas;
|
|
use Filament\Schemas\Schema;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Livewire\Attributes\Lazy;
|
|
use Livewire\Component;
|
|
|
|
#[Lazy]
|
|
class EncounterHistory extends Component implements HasSchemas
|
|
{
|
|
use InteractsWithSchemas;
|
|
|
|
public $data = [];
|
|
|
|
public $betsapi_id;
|
|
|
|
public $home;
|
|
|
|
public $away;
|
|
|
|
public function eventsInfolist(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->record($this->getData())
|
|
->components([
|
|
Tabs::make('Tabs')
|
|
->tabs([
|
|
Tab::make($this->home.' vs '.$this->away)
|
|
->schema([
|
|
RepeatableEntry::make('results.h2h')
|
|
->label('Direct encounters')
|
|
->table([
|
|
TableColumn::make('League'),
|
|
TableColumn::make('Date'),
|
|
TableColumn::make('Home'),
|
|
TableColumn::make('Away'),
|
|
TableColumn::make('Result'),
|
|
])
|
|
->schema([
|
|
TextEntry::make('league.name'),
|
|
TextEntry::make('time')->formatStateUsing(function ($state) {
|
|
return Carbon::createFromTimestamp($state)->format('d. m. Y H:i');
|
|
}),
|
|
TextEntry::make('home.name'),
|
|
TextEntry::make('away.name'),
|
|
TextEntry::make('ss'),
|
|
]),
|
|
]),
|
|
Tab::make($this->home)
|
|
->schema([
|
|
RepeatableEntry::make('results.home')
|
|
->label('The last games of '.$this->home)
|
|
->table([
|
|
TableColumn::make('League'),
|
|
TableColumn::make('Date'),
|
|
TableColumn::make('Home'),
|
|
TableColumn::make('Away'),
|
|
TableColumn::make('Result'),
|
|
])
|
|
->schema([
|
|
TextEntry::make('league.name'),
|
|
TextEntry::make('time')->formatStateUsing(function ($state) {
|
|
return Carbon::createFromTimestamp($state)->format('d. m. Y H:i');
|
|
}),
|
|
TextEntry::make('home.name'),
|
|
TextEntry::make('away.name'),
|
|
TextEntry::make('ss'),
|
|
]),
|
|
]),
|
|
Tab::make($this->away)
|
|
->schema([
|
|
RepeatableEntry::make('results.away')
|
|
->label('The last games of '.$this->away)
|
|
->table([
|
|
TableColumn::make('League'),
|
|
TableColumn::make('Date'),
|
|
TableColumn::make('Home'),
|
|
TableColumn::make('Away'),
|
|
TableColumn::make('Result'),
|
|
])
|
|
->schema([
|
|
TextEntry::make('league.name'),
|
|
TextEntry::make('time')->formatStateUsing(function ($state) {
|
|
return Carbon::createFromTimestamp($state)->format('d. m. Y H:i');
|
|
}),
|
|
TextEntry::make('home.name'),
|
|
TextEntry::make('away.name'),
|
|
TextEntry::make('ss'),
|
|
]),
|
|
]),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function mount($betsapi_id, $home, $away)
|
|
{
|
|
$this->betsapi_id = $betsapi_id;
|
|
$this->home = $home;
|
|
$this->away = $away;
|
|
}
|
|
|
|
public function getHome()
|
|
{
|
|
return $this->home;
|
|
}
|
|
|
|
public function getAway()
|
|
{
|
|
return $this->away;
|
|
}
|
|
|
|
public function getData()
|
|
{
|
|
return Http::get('https://api.b365api.com/v1/event/history?token='.config('env.betsapi_token').'&event_id='.$this->betsapi_id)->json();
|
|
}
|
|
}
|