F
Filamentβ€’16mo ago
Becker Maxime

Widgets v2 to v3

how to create a tablewidget or formwidget on v3 ?
5 Replies
RickDB
RickDBβ€’16mo ago
You can for example pass a view with a livewire component
Becker Maxime
Becker MaximeOPβ€’16mo ago
so is it possible to do this before ? exemple :
<?php

namespace App\Filament\Resources\CandidateResource\Widgets;

use App\Models\Candidate;
use App\Models\ContractType;
use App\Models\Job;
use App\Models\Place;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Widgets\Widget;

class DetailsCandidate extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.resources.candidate-resource.widgets.details-candidate';
protected int|string|array $columnSpan = 'full';

public function mount(): void
{

}

protected function getFormSchema(): array
{

return [
];
}
}
<?php

namespace App\Filament\Resources\CandidateResource\Widgets;

use App\Models\Candidate;
use App\Models\ContractType;
use App\Models\Job;
use App\Models\Place;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Widgets\Widget;

class DetailsCandidate extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.resources.candidate-resource.widgets.details-candidate';
protected int|string|array $columnSpan = 'full';

public function mount(): void
{

}

protected function getFormSchema(): array
{

return [
];
}
}
toeknee
toekneeβ€’16mo ago
Why wouldn't it be? You will likely have to update name spacing etc. But Just do a: php artisan make:filament-widget DetailsCandidate and implement your desired form and code
Kleis
Kleisβ€’16mo ago
The TableWidget now uses fluent style instead of "magically named functions", just a bit of moving parts around and looks much better πŸ‘
<?php

namespace App\Filament\Widgets;

use Closure;
use Filament\Tables;
use Filament\Widgets\TableWidget;
use Illuminate\Database\Eloquent\Builder;
use Filament\Tables\Table;

class OpenOrders extends TableWidget
{
protected static ?int $sort = 10;

public function table(Table $table): Table
{
return $table
->query(\App\Models\Order::where("status_id", 2)->orderBy('id', 'desc'))
->columns([
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('full_name')->label(__('Name')),
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
])
->recordUrl(
fn (\App\Models\Order $record): string => route('orders.show', ['order' => $record->id])
)
;
}
}
<?php

namespace App\Filament\Widgets;

use Closure;
use Filament\Tables;
use Filament\Widgets\TableWidget;
use Illuminate\Database\Eloquent\Builder;
use Filament\Tables\Table;

class OpenOrders extends TableWidget
{
protected static ?int $sort = 10;

public function table(Table $table): Table
{
return $table
->query(\App\Models\Order::where("status_id", 2)->orderBy('id', 'desc'))
->columns([
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('full_name')->label(__('Name')),
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
])
->recordUrl(
fn (\App\Models\Order $record): string => route('orders.show', ['order' => $record->id])
)
;
}
}
Want results from more Discord servers?
Add your server