feat: Enhance Filament Widgets
This commit is contained in:
@@ -4,7 +4,8 @@ namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Photo;
|
||||
use Filament\Actions;
|
||||
|
||||
class RecentPhotosTable extends BaseWidget
|
||||
{
|
||||
@@ -13,10 +14,12 @@ class RecentPhotosTable extends BaseWidget
|
||||
|
||||
public function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
$query = DB::table('photos')->orderByDesc('created_at')->limit(10);
|
||||
|
||||
return $table
|
||||
->query($query)
|
||||
->query(
|
||||
Photo::query()
|
||||
->orderByDesc('created_at')
|
||||
->limit(10)
|
||||
)
|
||||
->columns([
|
||||
Tables\Columns\ImageColumn::make('thumbnail_path')->label('Thumb')->circular(),
|
||||
Tables\Columns\TextColumn::make('id')->label('#'),
|
||||
@@ -25,14 +28,14 @@ class RecentPhotosTable extends BaseWidget
|
||||
Tables\Columns\TextColumn::make('created_at')->since(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\Action::make('feature')
|
||||
Actions\Action::make('feature')
|
||||
->label('Feature')
|
||||
->visible(fn($record) => ! (bool)($record->is_featured ?? 0))
|
||||
->action(fn($record) => DB::table('photos')->where('id', $record->id)->update(['is_featured' => 1, 'updated_at' => now()])),
|
||||
Tables\Actions\Action::make('unfeature')
|
||||
->visible(fn(Photo $record) => ! (bool)($record->is_featured ?? 0))
|
||||
->action(fn(Photo $record) => $record->update(['is_featured' => 1])),
|
||||
Actions\Action::make('unfeature')
|
||||
->label('Unfeature')
|
||||
->visible(fn($record) => (bool)($record->is_featured ?? 0))
|
||||
->action(fn($record) => DB::table('photos')->where('id', $record->id)->update(['is_featured' => 0, 'updated_at' => now()])),
|
||||
->visible(fn(Photo $record) => (bool)($record->is_featured ?? 0))
|
||||
->action(fn(Photo $record) => $record->update(['is_featured' => 0])),
|
||||
])
|
||||
->paginated(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user