ProjektMethodesRelationManager
This commit is contained in:
1 parent
77f8b3c047
commit
9a7e6fa248
11 files changed
+209
-29
No files matched your search
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Projektes\RelationManagers;
|
||||
|
||||
use App\Actions\CreateProjektMethoden;
|
||||
use App\Models\Methode;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables\Columns\SelectColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\TextInputColumn;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ProjektMethodesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'projekt_methodes';
|
||||
|
||||
protected static ?string $title = 'Raum Methode';
|
||||
|
||||
protected static ?string $navigationLabel = 'Raum Methoden';
|
||||
|
||||
protected static ?string $modelLabel = 'Raum Methoden';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Raum Methoden';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('raumart')
|
||||
->columns([
|
||||
SelectColumn::make('methode_id')
|
||||
->options(Methode::query()->pluck('name', 'id')),
|
||||
TextColumn::make('raumart')
|
||||
->searchable(),
|
||||
TextInputColumn::make('faktor')
|
||||
->suffixIcon('phosphor-function')
|
||||
->width('1rem')
|
||||
->rules(['required', 'faktor' => 'decimal:0,2'])
|
||||
->searchable(),
|
||||
])
|
||||
->filters([
|
||||
TernaryFilter::make('methode_id')
|
||||
->label('Methode zugeordnet'),
|
||||
])
|
||||
->headerActions([
|
||||
Action::make('erstellen')
|
||||
->action(fn (CreateProjektMethoden $createProjektMethoden) => $createProjektMethoden->create($this->ownerRecord))
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Raum Methoden erstellen')
|
||||
->modalDescription('Alle bestehenden Daten in dieser Tabelle werden vorher gelöscht.')
|
||||
->modalSubmitActionLabel('Erstellen')
|
||||
->label('Erstellen')
|
||||
->tooltip('Daten werden aus "Räume Alle" Tabelle gefiltert.')
|
||||
->icon('heroicon-o-cog-8-tooth'),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
BulkAction::make('faktor')
|
||||
->color('primary')
|
||||
->label('Faktor zuweisen')
|
||||
->schema([
|
||||
TextInput::make('faktor')
|
||||
->prefixIcon('phosphor-function')
|
||||
->numeric()
|
||||
->required(),
|
||||
])
|
||||
->icon('phosphor-function')
|
||||
->action(function (Collection $records, array $data): void {
|
||||
foreach ($records as $record) {
|
||||
ProjektMethode::where('id', '=', $record->id)
|
||||
->update(
|
||||
['faktor' => $data['faktor']]
|
||||
);
|
||||
}
|
||||
}),
|
||||
BulkAction::make('methode')
|
||||
->color('primary')
|
||||
->label('Methode zuweisen')
|
||||
->schema([
|
||||
TextInput::make('faktor')
|
||||
->prefixIcon('phosphor-calculator')
|
||||
->numeric()
|
||||
->required(),
|
||||
])
|
||||
->icon('phosphor-calculator')
|
||||
->action(function (Collection $records, array $data): void {
|
||||
foreach ($records as $record) {
|
||||
ProjektMethode::where('id', '=', $record->id)
|
||||
->update(
|
||||
['faktor' => $data['faktor']]
|
||||
);
|
||||
}
|
||||
}),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user