Files
einundzwanzig-portal/app/Http/Livewire/Tables/BitcoinEventTable.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

100 lines
3.6 KiB
PHP

<?php
namespace App\Http\Livewire\Tables;
use App\Models\BitcoinEvent;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;
class BitcoinEventTable extends DataTableComponent
{
public string $country;
public string $tableName = 'bitcoin_events';
public function configure(): void
{
$this->setPrimaryKey('id')
->setDefaultSort('from', 'asc')
->setAdditionalSelects([
'bitcoin_events.id',
'bitcoin_events.venue_id',
])
->setThAttributes(function (Column $column) {
return [
'class' => 'px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:bg-gray-800 dark:text-gray-400',
'default' => false,
];
})
->setTdAttributes(function (Column $column, $row, $columnIndex, $rowIndex) {
return [
'class' => 'px-6 py-4 text-sm font-medium dark:text-white',
'default' => false,
];
})
->setColumnSelectStatus(false)
->setPerPage(10);
}
public function filters(): array
{
return [
TextFilter::make('Event by ID', 'byid')
->hiddenFromMenus()
->filter(function (Builder $builder, string $value) {
$builder->whereIn('bitcoin_events.id', str($value)->explode(','));
}),
];
}
public function columns(): array
{
return [
Column::make(__('Country'), 'venue.city.country.name')
->format(
fn ($value, $row, Column $column) => view('columns.bitcoin_events.country')->withRow($row)
)
->sortable()
->collapseOnMobile(),
Column::make(__('Title'), 'title')
->format(
fn ($value, $row, Column $column) => view('columns.bitcoin_events.title')->withRow($row)
)
->sortable(),
Column::make(__('From'), 'from')
->format(
fn ($value, $row, Column $column) => $value->asDateTime()
),
Column::make(__('To'), 'to')
->format(
fn ($value, $row, Column $column) => $value->asDateTime()
)
->collapseOnMobile(),
Column::make(__('Venue'), 'venue.name')
->collapseOnMobile(),
Column::make(__('Link'), 'link')
->format(
fn ($value, $row, Column $column) => view('columns.bitcoin_events.link')->withRow($row)
)
->sortable()
->collapseOnMobile(),
];
}
public function builder(): Builder
{
return BitcoinEvent::query()
->with([
'venue.city.country',
])
->where('bitcoin_events.from', '>=', now())
->where(fn ($query) => $query
->whereHas('venue.city.country',
fn ($query) => $query->where('code', $this->country))
->orWhere('show_worldwide', true)
);
}
}