ProjektMethodesRelationManager

This commit is contained in:
salam committed 2025-10-06 08:57:21 +02:00
1 parent 77f8b3c047
commit 9a7e6fa248
11 files changed
+209 -29

No files matched your search

+2 -2
View File
@@ -1,4 +1,4 @@
a make:model Customer -ms a make:model ProjektMethode -ms
a make:filament-resource Customer a make:filament-resource Customer
@@ -29,7 +29,7 @@ php artisan make:filament-importer Raeumealle
A make:filament-resource Allgemeinflaechen --nested A make:filament-resource Allgemeinflaechen --nested
php artisan make:filament-relation-manager Raeumealle lessons title a make:filament-relation-manager Projekte;ethodeResource projekt_methodes raumart
for import in prod run for import in prod run
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Actions;
use App\Models\ProjektMethode;
use App\Models\Raeumealle;
class CreateProjektMethoden
{
public function create($record)
{
ProjektMethode::where('projekte_id', $record->id)->delete();
$raeumealles = Raeumealle::where('projekte_id', $record->id)->get();
foreach ($raeumealles as $raeumealle) {
ProjektMethode::firstOrCreate([
'projekte_id' => $record->id,
'raumart' => $raeumealle->raumart,
]);
}
}
}
@@ -21,7 +21,7 @@ class MethodeResource extends Resource
protected static string|UnitEnum|null $navigationGroup = 'Vorlagen'; protected static string|UnitEnum|null $navigationGroup = 'Vorlagen';
protected static string|BackedEnum|null $navigationIcon = 'lucide-calculator'; protected static string|BackedEnum|null $navigationIcon = 'phosphor-calculator';
protected static ?string $navigationLabel = 'Methode'; protected static ?string $navigationLabel = 'Methode';
@@ -2,11 +2,10 @@
namespace App\Filament\Resources\Projektes; namespace App\Filament\Resources\Projektes;
use App\Filament\Clusters\Projekte\ProjekteCluster;
use App\Filament\Resources\Projektes\Pages\CreateProjekte;
use App\Filament\Resources\Projektes\Pages\EditProjekte; use App\Filament\Resources\Projektes\Pages\EditProjekte;
use App\Filament\Resources\Projektes\Pages\ListProjektes; use App\Filament\Resources\Projektes\Pages\ListProjektes;
use App\Filament\Resources\Projektes\RelationManagers\AllgemeinflaechensRelationManager; use App\Filament\Resources\Projektes\RelationManagers\AllgemeinflaechensRelationManager;
use App\Filament\Resources\Projektes\RelationManagers\ProjektMethodesRelationManager;
use App\Filament\Resources\Projektes\RelationManagers\RaeumeallesRelationManager; use App\Filament\Resources\Projektes\RelationManagers\RaeumeallesRelationManager;
use App\Filament\Resources\Projektes\Schemas\ProjekteForm; use App\Filament\Resources\Projektes\Schemas\ProjekteForm;
use App\Filament\Resources\Projektes\Tables\ProjektesTable; use App\Filament\Resources\Projektes\Tables\ProjektesTable;
@@ -24,8 +23,6 @@ class ProjekteResource extends Resource
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
// protected static ?string $cluster = ProjekteCluster::class;
protected static ?string $recordTitleAttribute = 'interner_name'; protected static ?string $recordTitleAttribute = 'interner_name';
protected static ?string $navigationLabel = 'Projekte'; protected static ?string $navigationLabel = 'Projekte';
@@ -49,6 +46,7 @@ class ProjekteResource extends Resource
return [ return [
AllgemeinflaechensRelationManager::class, AllgemeinflaechensRelationManager::class,
RaeumeallesRelationManager::class, RaeumeallesRelationManager::class,
ProjektMethodesRelationManager::class,
]; ];
} }
@@ -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']]
);
}
}),
]),
]);
}
}
@@ -55,7 +55,7 @@ class RaeumeallesRelationManager extends RelationManager
TextColumn::make('geschoss')->searchable(), TextColumn::make('geschoss')->searchable(),
TextColumn::make('raumart')->searchable(), TextColumn::make('raumart')->searchable(),
TextInputColumn::make('faktor') TextInputColumn::make('faktor')
->suffixIcon('phosphor-calculator') ->suffixIcon('phosphor-function')
->width('1rem') ->width('1rem')
->rules(['required', 'faktor' => 'decimal:0,2']) ->rules(['required', 'faktor' => 'decimal:0,2'])
->searchable(), ->searchable(),
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProjektMethode extends Model
{
protected $fillable = [
'projekte_id',
'methode_id',
'geschoss',
'raumart',
'flaeche',
];
public function methodes()
{
return $this->hasMany(Methode::class);
}
}
+5
View File
@@ -36,4 +36,9 @@ class Projekte extends Model
{ {
return $this->hasMany(Raeumealle::class); return $this->hasMany(Raeumealle::class);
} }
public function projekt_methodes()
{
return $this->hasMany(ProjektMethode::class);
}
} }
+1
View File
@@ -29,6 +29,7 @@
'app.filament.resources.projektes.pages.edit-projekte' => 'App\\Filament\\Resources\\Projektes\\Pages\\EditProjekte', 'app.filament.resources.projektes.pages.edit-projekte' => 'App\\Filament\\Resources\\Projektes\\Pages\\EditProjekte',
'app.filament.resources.projektes.pages.list-projektes' => 'App\\Filament\\Resources\\Projektes\\Pages\\ListProjektes', 'app.filament.resources.projektes.pages.list-projektes' => 'App\\Filament\\Resources\\Projektes\\Pages\\ListProjektes',
'app.filament.resources.projektes.relation-managers.allgemeinflaechens-relation-manager' => 'App\\Filament\\Resources\\Projektes\\RelationManagers\\AllgemeinflaechensRelationManager', 'app.filament.resources.projektes.relation-managers.allgemeinflaechens-relation-manager' => 'App\\Filament\\Resources\\Projektes\\RelationManagers\\AllgemeinflaechensRelationManager',
'app.filament.resources.projektes.relation-managers.projekt-methodes-relation-manager' => 'App\\Filament\\Resources\\Projektes\\RelationManagers\\ProjektMethodesRelationManager',
'app.filament.resources.projektes.relation-managers.raeumealles-relation-manager' => 'App\\Filament\\Resources\\Projektes\\RelationManagers\\RaeumeallesRelationManager', 'app.filament.resources.projektes.relation-managers.raeumealles-relation-manager' => 'App\\Filament\\Resources\\Projektes\\RelationManagers\\RaeumeallesRelationManager',
'app.filament.resources.textblocks.pages.create-textblock' => 'App\\Filament\\Resources\\Textblocks\\Pages\\CreateTextblock', 'app.filament.resources.textblocks.pages.create-textblock' => 'App\\Filament\\Resources\\Textblocks\\Pages\\CreateTextblock',
'app.filament.resources.textblocks.pages.edit-textblock' => 'App\\Filament\\Resources\\Textblocks\\Pages\\EditTextblock', 'app.filament.resources.textblocks.pages.edit-textblock' => 'App\\Filament\\Resources\\Textblocks\\Pages\\EditTextblock',
+21 -21
View File
@@ -511,7 +511,7 @@ app('router')->setCompiledRoutes(
array ( array (
0 => 0 =>
array ( array (
'_route' => 'generated::ZKAnD1JupDI6nRdd', '_route' => 'generated::NzP4VI5PeVTSNa8b',
), ),
1 => NULL, 1 => NULL,
2 => 2 =>
@@ -531,7 +531,7 @@ app('router')->setCompiledRoutes(
array ( array (
0 => 0 =>
array ( array (
'_route' => 'generated::s39ttVgluaaTSPQs', '_route' => 'generated::pt0LAwcB1sGBW4Oo',
), ),
1 => NULL, 1 => NULL,
2 => 2 =>
@@ -589,7 +589,7 @@ app('router')->setCompiledRoutes(
array ( array (
0 => 0 =>
array ( array (
'_route' => 'generated::GTqxIeXqrS3yeXC2', '_route' => 'generated::AOiPiqGBrqXDsS0D',
), ),
1 => NULL, 1 => NULL,
2 => 2 =>
@@ -609,7 +609,7 @@ app('router')->setCompiledRoutes(
array ( array (
0 => 0 =>
array ( array (
'_route' => 'generated::CqHTEVGG8Ecd113F', '_route' => 'generated::P6HogTayo2iWezmY',
), ),
1 => NULL, 1 => NULL,
2 => 2 =>
@@ -629,7 +629,7 @@ app('router')->setCompiledRoutes(
array ( array (
0 => 0 =>
array ( array (
'_route' => 'generated::cIETyLf8UfA6kLWN', '_route' => 'generated::MTlI6TBwxyNMQmB6',
), ),
1 => NULL, 1 => NULL,
2 => 2 =>
@@ -649,7 +649,7 @@ app('router')->setCompiledRoutes(
array ( array (
0 => 0 =>
array ( array (
'_route' => 'generated::vAq2m1K8fDxzN7CD', '_route' => 'generated::hTSXazyycB1PbjMf',
), ),
1 => NULL, 1 => NULL,
2 => 2 =>
@@ -669,7 +669,7 @@ app('router')->setCompiledRoutes(
array ( array (
0 => 0 =>
array ( array (
'_route' => 'generated::PslwnVFq3OKf1wWj', '_route' => 'generated::72CUCq6E4ZsFkqBN',
), ),
1 => NULL, 1 => NULL,
2 => 2 =>
@@ -2595,7 +2595,7 @@ app('router')->setCompiledRoutes(
'waitSeconds' => NULL, 'waitSeconds' => NULL,
'withTrashed' => false, 'withTrashed' => false,
), ),
'generated::ZKAnD1JupDI6nRdd' => 'generated::NzP4VI5PeVTSNa8b' =>
array ( array (
'methods' => 'methods' =>
array ( array (
@@ -2607,7 +2607,7 @@ app('router')->setCompiledRoutes(
array ( array (
'uses' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@returnJavaScriptAsFile', 'uses' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@returnJavaScriptAsFile',
'controller' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@returnJavaScriptAsFile', 'controller' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@returnJavaScriptAsFile',
'as' => 'generated::ZKAnD1JupDI6nRdd', 'as' => 'generated::NzP4VI5PeVTSNa8b',
), ),
'fallback' => false, 'fallback' => false,
'defaults' => 'defaults' =>
@@ -2623,7 +2623,7 @@ app('router')->setCompiledRoutes(
'waitSeconds' => NULL, 'waitSeconds' => NULL,
'withTrashed' => false, 'withTrashed' => false,
), ),
'generated::s39ttVgluaaTSPQs' => 'generated::pt0LAwcB1sGBW4Oo' =>
array ( array (
'methods' => 'methods' =>
array ( array (
@@ -2635,7 +2635,7 @@ app('router')->setCompiledRoutes(
array ( array (
'uses' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@maps', 'uses' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@maps',
'controller' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@maps', 'controller' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@maps',
'as' => 'generated::s39ttVgluaaTSPQs', 'as' => 'generated::pt0LAwcB1sGBW4Oo',
), ),
'fallback' => false, 'fallback' => false,
'defaults' => 'defaults' =>
@@ -2737,7 +2737,7 @@ app('router')->setCompiledRoutes(
'waitSeconds' => NULL, 'waitSeconds' => NULL,
'withTrashed' => false, 'withTrashed' => false,
), ),
'generated::GTqxIeXqrS3yeXC2' => 'generated::AOiPiqGBrqXDsS0D' =>
array ( array (
'methods' => 'methods' =>
array ( array (
@@ -2766,7 +2766,7 @@ app('router')->setCompiledRoutes(
\'exception\' => $exception, \'exception\' => $exception,
]), status: $exception ? 500 : 200); ]), status: $exception ? 500 : 200);
}";s:5:"scope";s:54:"Illuminate\\Foundation\\Configuration\\ApplicationBuilder";s:4:"this";N;s:4:"self";s:32:"0000000000000f2c0000000000000000";}}', }";s:5:"scope";s:54:"Illuminate\\Foundation\\Configuration\\ApplicationBuilder";s:4:"this";N;s:4:"self";s:32:"0000000000000f2c0000000000000000";}}',
'as' => 'generated::GTqxIeXqrS3yeXC2', 'as' => 'generated::AOiPiqGBrqXDsS0D',
), ),
'fallback' => false, 'fallback' => false,
'defaults' => 'defaults' =>
@@ -2782,7 +2782,7 @@ app('router')->setCompiledRoutes(
'waitSeconds' => NULL, 'waitSeconds' => NULL,
'withTrashed' => false, 'withTrashed' => false,
), ),
'generated::CqHTEVGG8Ecd113F' => 'generated::P6HogTayo2iWezmY' =>
array ( array (
'methods' => 'methods' =>
array ( array (
@@ -2804,7 +2804,7 @@ app('router')->setCompiledRoutes(
'where' => 'where' =>
array ( array (
), ),
'as' => 'generated::CqHTEVGG8Ecd113F', 'as' => 'generated::P6HogTayo2iWezmY',
), ),
'fallback' => false, 'fallback' => false,
'defaults' => 'defaults' =>
@@ -2820,7 +2820,7 @@ app('router')->setCompiledRoutes(
'waitSeconds' => NULL, 'waitSeconds' => NULL,
'withTrashed' => false, 'withTrashed' => false,
), ),
'generated::cIETyLf8UfA6kLWN' => 'generated::MTlI6TBwxyNMQmB6' =>
array ( array (
'methods' => 'methods' =>
array ( array (
@@ -2842,7 +2842,7 @@ app('router')->setCompiledRoutes(
'where' => 'where' =>
array ( array (
), ),
'as' => 'generated::cIETyLf8UfA6kLWN', 'as' => 'generated::MTlI6TBwxyNMQmB6',
), ),
'fallback' => false, 'fallback' => false,
'defaults' => 'defaults' =>
@@ -2858,7 +2858,7 @@ app('router')->setCompiledRoutes(
'waitSeconds' => NULL, 'waitSeconds' => NULL,
'withTrashed' => false, 'withTrashed' => false,
), ),
'generated::vAq2m1K8fDxzN7CD' => 'generated::hTSXazyycB1PbjMf' =>
array ( array (
'methods' => 'methods' =>
array ( array (
@@ -2880,7 +2880,7 @@ app('router')->setCompiledRoutes(
'where' => 'where' =>
array ( array (
), ),
'as' => 'generated::vAq2m1K8fDxzN7CD', 'as' => 'generated::hTSXazyycB1PbjMf',
), ),
'fallback' => false, 'fallback' => false,
'defaults' => 'defaults' =>
@@ -2896,7 +2896,7 @@ app('router')->setCompiledRoutes(
'waitSeconds' => NULL, 'waitSeconds' => NULL,
'withTrashed' => false, 'withTrashed' => false,
), ),
'generated::PslwnVFq3OKf1wWj' => 'generated::72CUCq6E4ZsFkqBN' =>
array ( array (
'methods' => 'methods' =>
array ( array (
@@ -2918,7 +2918,7 @@ app('router')->setCompiledRoutes(
'where' => 'where' =>
array ( array (
), ),
'as' => 'generated::PslwnVFq3OKf1wWj', 'as' => 'generated::72CUCq6E4ZsFkqBN',
), ),
'fallback' => false, 'fallback' => false,
'defaults' => 'defaults' =>
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('projekt_methodes', function (Blueprint $table) {
$table->id();
$table->foreignId('projekte_id')->constrained()->cascadeOnDelete();
$table->integer('methode_id')->default(0);
$table->string('geschoss')->nullable();
$table->string('raumart')->nullable();
$table->decimal('faktor', 5, 2)->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('projekt_methodes');
}
};