Workflow
Searchableraw

Uses searchableRaw() to search for an existing date with the format dd/mm/YYYY.

ID
Dish
Production date
1
Arkansas Possum Pie
28/11/2024
2
Albacore Tuna Melt
10/12/2024
3
Π±ΠΎΡ€Ρ‰
18/12/2024
4
Bacalhau com natas
01/12/2024
5
Baba Ghanoush
22/11/2024
6
Bacon Cheeseburger
18/12/2024
7
Baked potato
08/12/2024
8
Baklava
22/11/2024
9
Bangers and mash
25/11/2024
10
Black Pudding
24/11/2024
Showing 1 to 10 of 192 Results
Disclaimer: Table data is randomly generated for illustrative purposes only. The information here is not a reflection of the actual market and does not constitute business, financial, or medical advice.
πŸ”Ž View on GitHub
<?php

namespace App\Livewire\Examples\SearchablerawTable;

use App\Models\Dish;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
use PowerComponents\LivewirePowerGrid\Column;

use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;

final class SearchablerawTable extends PowerGridComponent
{
    public string $tableName = 'searchable-raw-table';

    public string $sortField = 'dishes.id';

    public function setUp(): array
    {
        $this->showCheckBox();

        return [
            PowerGrid::header()
                ->showSearchInput(),

            PowerGrid::footer()
                ->showPerPage()
                ->showRecordCount(),
        ];
    }

    public function datasource(): ?Builder
    {
        return Dish::query()->select('dishes.*');
    }

    public function fields(): PowerGridFields
    {
        return PowerGrid::fields()
            ->add('id')
            ->add('dish_name', fn ($dish) => e($dish->name))
            ->add('produced_at')
            ->add('produced_at_formatted', fn ($dish) => Carbon::parse($dish->produced_at)->format('d/m/Y'));
    }

    public function columns(): array
    {
        return [
            Column::add()
                ->title('ID')
                ->field('id')
                ->searchable()
                ->sortable(),

            Column::add()
                ->title('Dish')
                ->field('dish_name')
                ->searchable()
                ->sortable(),

            Column::add()
                ->title('Production date')
                ->field('produced_at_formatted')
                ->searchableRaw('DATE_FORMAT(dishes.produced_at, "%d/%m/%Y") like ?'),
        ];
    }
}