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
|
Chef
|
Price
|
In Stock
|
Created At
|
---|---|---|---|---|---|
41
|
Chocolate cheesecake
|
|
109.92
|
No
|
07/07/2024
|
42
|
Chowder
|
|
271.34
|
No
|
31/05/2024
|
43
|
Churrasco
|
|
245.44
|
No
|
18/05/2024
|
44
|
Cinnamon Roll
|
|
97.96
|
No
|
08/06/2024
|
45
|
Coleslaw
|
|
208.73
|
No
|
31/05/2024
|
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\Rule;use PowerComponents\LivewirePowerGrid\Footer;use PowerComponents\LivewirePowerGrid\Header;use PowerComponents\LivewirePowerGrid\PowerGrid;use PowerComponents\LivewirePowerGrid\PowerGridComponent;use PowerComponents\LivewirePowerGrid\PowerGridFields; final class ShowSoftDeleteTable extends PowerGridComponent{ public function setUp(): array { return [ Header::make() ->showSoftDeletes() ->showSearchInput(), Footer::make() ->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('chef_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('Chef', 'chef_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'), ]; }}
Code highlighting provided by Torchlight.dev
Here you can find all relevant packages installed on this demo.
Name
|
Version
|
Description
|
---|---|---|
laravel/framework
|
v11
|
The Laravel Framework.
|
livewire/livewire
|
v3.5.4
|
A front-end framework for Laravel.
|
openspout/openspout
|
v4.24.3
|
PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
|
power-components/livewire-powergrid
|
5.x-dev
|
PowerGrid generates Advanced Datatables using Laravel Livewire.
|