1, 'date' => null, 'comment' => '', ]; protected $model = BookCase::class; public function configure(): void { $this->setPrimaryKey('id') ->setAdditionalSelects(['id', 'homepage']) ->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(50); } public function filters(): array { return [ TextFilter::make('By IDs', 'byids') ->filter(function (Builder $builder, string $value) { $builder->whereIn('id', str($value)->explode(',')); }), ]; } public function columns(): array { return [ Column::make("Name", "title") ->sortable() ->searchable( function (Builder $query, $searchTerm) { $query->where('title', 'ilike', '%'.$searchTerm.'%'); } ), Column::make("Adresse", "address") ->sortable() ->searchable(), Column::make("Link") ->label( fn( $row, Column $column ) => $row->homepage ? 'Link' : null ) ->html(), Column::make('Orange-Pilled', 'orange_pilled') ->label(fn($row, Column $column) => view('columns.book_cases.oranged-pilled')->withRow($row)), ]; } private function url_to_absolute($url) { if (str($url)->contains('http')) { return $url; } if (!str($url)->contains('http')) { return str($url)->prepend('https://'); } } public function builder(): Builder { return BookCase::query() ->withCount([ 'orangePills', ]); } public function viewHistoryModal($modelId): void { $this->viewingModal = true; $this->currentModal = BookCase::findOrFail($modelId); } public function submit(): void { $this->validate([ 'orangepill.amount' => 'required|numeric', 'orangepill.date' => 'required|date', ]); $orangePill = OrangePill::create([ 'user_id' => auth()->id(), 'book_case_id' => $this->currentModal->id, 'amount' => $this->orangepill['amount'], 'date' => $this->orangepill['date'], ]); if ($this->orangepill['comment']) { $this->currentModal->comment($this->orangepill['comment']); } $this->resetModal(); $this->emit('refreshDatatable'); } public function resetModal(): void { $this->reset('viewingModal', 'currentModal'); } public function customView(): string { return 'modals.book_cases.orange_pill'; } }