Workflow
Show Soft Delete

This example uses the Display Soft Delete Items feature.

Click on the trash bin icon to display or hide soft deleted items. The dish ID #40 is soft deleted.

Without deleted
With deleted
Only deleted
ID
Name
Price
In Stock
Created At
41
Chocolate cheesecake
158.81
Yes
28/10/2024
42
Chowder
60.5
Yes
01/11/2024
43
Churrasco
167.37
Yes
19/11/2024
44
Cinnamon Roll
233.07
Yes
03/12/2024
45
Coleslaw
162.91
Yes
14/12/2024
Showing 1 to 5 of 5 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.
<?php

namespace App\Livewire\Examples\ShowSoftDeleteTable;

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\Facades\Rule;

use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;

final class ShowSoftDeleteTable extends PowerGridComponent
{
    public string $tableName = 'show-soft-delete-table';

    public function setUp(): array
    {
        return [
            PowerGrid::header()
                ->showSoftDeletes()
                ->showSearchInput(),

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

    public function datasource(): ?Builder
    {
        return Dish::with('category')->whereBetween('id', [40, 45]);
    }

    public function fields(): PowerGridFields
    {
        return PowerGrid::fields()
            ->add('id')
            ->add('name')
            ->add('price')
            ->add('in_stock')
            ->add('in_stock_label', fn ($entry) => $entry->in_stock ? 'Yes' : 'No')
            ->add('created_at', fn ($entry) => Carbon::parse($entry->created_at))
            ->add('created_at_formatted', fn ($entry) => Carbon::parse($entry->created_at)->format('d/m/Y'));
    }

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

            Column::make('Name', 'name')
                ->searchable()
                ->sortable(),

            Column::make('Price', 'price')
                ->sortable(),

            Column::make('In Stock', 'in_stock_label', 'in_stock'),

            Column::make('Created At', 'created_at_formatted'),
        ];
    }

    public function actionRules(): array
    {
        return [
            Rule::rows()
                ->when(fn ($dish) => $dish->trashed())
                ->setAttribute('class', 'bg-red-200'),
        ];
    }
}