crear una taula PowerGrid
Created at: 2025-01-15 15:35:49 | Updated at: 2025-01-15 15:42:16
php artisan powergrid:create
<?php namespace App\Livewire; use App\Models\FacturaCompra; use Illuminate\Support\Carbon; 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\Responsive; final class FacturaCompraTable extends PowerGridComponent { public string $tableName = 'factura-compra-table-dneqqk-table'; public function setUp(): array { $this->showCheckBox(); return [ PowerGrid::header() ->showSearchInput() ->showToggleColumns(), PowerGrid::footer() ->showPerPage() ->showRecordCount(), ]; } public function datasource(): Builder { return FacturaCompra::query() ->join('proveidors', 'facturascompras.proveidor_id', '=', 'proveidors.id') ->select('facturascompras.*', 'proveidors.raosocial as proveidor_raosocial'); } public function relationSearch(): array { return [ 'proveidor' => [ 'raosocial', ], ]; } public function fields(): PowerGridFields { return PowerGrid::fields() ->add('id') ->add('proveidor_raosocial', fn (FacturaCompra $model) => '<a class="underline text-blue-600 hover:text-blue-800" href="'.url('/admin/factura-compras/'.$model->id.'/edit').'">'.$model->proveidor->raosocial.'</a>') ->add('data_formatted', fn (FacturaCompra $model) => Carbon::parse($model->data)->format('d/m/Y')) ->add('totalsenseiva') ->add('iva') ->add('totalambiva') ->add('total') ->add('url_factura') ->add('created_at'); } public function columns(): array { return [ Column::make('Id', 'id') ->sortable() ->searchable(), Column::make('Proveidor', 'proveidor_raosocial') ->sortable() ->searchable(), Column::make('Data', 'data_formatted', 'data') ->sortable(), Column::make('Totalsenseiva', 'totalsenseiva') ->sortable() ->searchable(), Column::make('Iva', 'iva') ->sortable() ->searchable(), Column::make('Totalambiva', 'totalambiva') ->sortable() ->searchable(), Column::make('Total', 'total') ->sortable() ->searchable(), Column::make('Url factura', 'url_factura') ->sortable() ->searchable(), Column::make('Created at', 'created_at_formatted', 'created_at') ->sortable(), Column::make('Created at', 'created_at') ->sortable() ->searchable(), ]; } public function filters(): array { return [ Filter::datepicker('data'), ]; } #[\Livewire\Attributes\On('edit')] public function edit($rowId): void { $this->js('alert('.$rowId.')'); } }
No valid image directory found or the category is not valid for the gallery.