KTVCentral/app/Livewire/Admin/BranchTable.php
allen.yan 7c8c3fe69b DB 滙入
User 介面 只能看資料不能做修改
Role 介面移除
Branch介面 只能看資料不能做修改
Room 介面 可操控 包廂開關台
Sqgger API 可操控API
Room 有操控異動記錄
machine_statuses 需做資料留存需留7 天
20250528
2025-05-28 09:24:03 +08:00

90 lines
2.8 KiB
PHP

<?php
namespace App\Livewire\Admin;
use App\Models\Branch;
use App\Jobs\ExportSqliteBranchJob;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Blade;
use Illuminate\Database\Eloquent\Builder;
use PowerComponents\LivewirePowerGrid\Button;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\Traits\WithExport;
use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable;
use PowerComponents\LivewirePowerGrid\Facades\Rule;
use Livewire\Attributes\On;
use WireUi\Traits\WireUiActions;
final class BranchTable extends PowerGridComponent
{
use WithExport, WireUiActions;
public string $tableName = 'branch-table';
public bool $showFilters = false;
public function boot(): void
{
config(['livewire-powergrid.filter' => 'outside']);
}
public function setUp(): array
{
$actions = [];
$header = PowerGrid::header()
->withoutLoading()
->showToggleColumns();
$header->includeViewOnTop('livewire.admin.branch-header') ;
$actions[]=$header;
$actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
return $actions;
}
public function datasource(): Builder
{
return Branch::query();
}
public function relationSearch(): array
{
return [];
}
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('name')
->add('external_ip')
->add('enable')
->add('created_at_formatted', fn (Branch $model) => Carbon::parse($model->created_at)->format('d/m/Y H:i:s'));
}
public function columns(): array
{
$column=[];
$column[]=Column::make(__('branches.no'), 'id');
$column[]=Column::make(__('branches.name'), 'name')->sortable()->searchable();
$column[]=Column::make(__('branches.external_ip'), 'external_ip')->sortable()->searchable();
$column[]=Column::make(__('branches.enable'), 'enable');
$column[]=Column::make('Created at', 'created_at_formatted', 'created_at')->sortable()->hidden(true, false);
return $column;
}
public function filters(): array
{
return [
Filter::inputText('name')->placeholder(__('branches.name')),
Filter::inputText('external_ip')->placeholder(__('branches.external_ip')),
Filter::boolean('enable')->label('✅', '❌'),
Filter::datetimepicker('created_at'),
];
}
}