78 lines
2.4 KiB
PHP
78 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Projektes\Widgets;
|
|
|
|
use App\Models\Merkmale;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Filament\Widgets\TableWidget;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class WidgetMerkmale extends TableWidget
|
|
{
|
|
// protected static ?string $title = 'Merkmale';
|
|
|
|
// protected static ?string $navigationLabel = 'Merkmale';
|
|
|
|
// protected static ?string $pluralModelLabel = 'Merkmale';
|
|
|
|
// protected static ?string $modelLabel = 'Merkmale';
|
|
|
|
protected static ?string $title = 'Merkmale';
|
|
|
|
public $projekte_id;
|
|
|
|
// public function mount(): void
|
|
// {
|
|
// dd($this->projekte_id);
|
|
// // $this->data = $this->ownerRecord;
|
|
// }
|
|
|
|
// $livewire->ownerRecord or $this->ownerRecord
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->query(fn (): Builder => Merkmale::where('projekte_id', $this->projekte_id))
|
|
->columns([
|
|
TextColumn::make('name'),
|
|
])
|
|
->paginated(false)
|
|
->recordActions([
|
|
EditAction::make()
|
|
->color('gray')
|
|
->iconButton()
|
|
->schema([
|
|
TextInput::make('name')
|
|
->required()
|
|
->maxLength(255),
|
|
]),
|
|
DeleteAction::make()
|
|
->color('gray')
|
|
->iconButton(),
|
|
])
|
|
->headerActions([
|
|
Action::make('name')
|
|
->icon('phosphor-plus')
|
|
->label('Merkmal')
|
|
->schema([
|
|
TextInput::make('name')
|
|
->prefixIcon('phosphor-house-simple'),
|
|
])
|
|
->action(function (array $data) {
|
|
$code = Merkmale::getfreecode($this->projekte_id);
|
|
if ($code) {
|
|
$merkmal = new Merkmale;
|
|
$merkmal->projekte_id = $this->projekte_id;
|
|
$merkmal->code = $code;
|
|
$merkmal->name = $data['name'];
|
|
$merkmal->save();
|
|
}
|
|
}),
|
|
]);
|
|
}
|
|
}
|