Skip to content

Commit

Permalink
feat: created geolocation and organism resources and their relation m…
Browse files Browse the repository at this point in the history
…anagers for molecule resource
  • Loading branch information
sriramkanakam87 committed Apr 25, 2024
1 parent 3e43bea commit c51050c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\AttachAction;

class GeoLocationRelationManager extends RelationManager
{
Expand All @@ -30,15 +31,26 @@ public function table(Table $table): Table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('locations'),
])
->filters([
//
])
->headerActions([
Tables\Actions\AttachAction::make()
->multiple(),
->preloadRecordSelect()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('locations')
]),
])
->actions([
Tables\Actions\EditAction::make()
->form(function ($action) {
return [
Forms\Components\TextInput::make('locations'),
];
}),
Tables\Actions\DetachAction::make(),
])
->bulkActions([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\AttachAction;
use Filament\Tables\Actions\EditAction;
use App\Models\Organism;

class OrganismsRelationManager extends RelationManager
{
Expand All @@ -30,15 +34,30 @@ public function table(Table $table): Table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('organism_parts'),
])
// ->allowDuplicates()
->filters([
//
])
->headerActions([
Tables\Actions\AttachAction::make()
->multiple(),
->preloadRecordSelect()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('organism_parts')
]),
])
->actions([
Tables\Actions\EditAction::make()
->form(function ($action) {
return [
Forms\Components\TextInput::make('organism_parts'),
];
}),
// ->mountUsing(
// fn($record, $form) => $form->fill($record->pivot->toArray())
// ),
Tables\Actions\DetachAction::make(),
])
->bulkActions([
Expand Down
2 changes: 1 addition & 1 deletion app/Models/GeoLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class GeoLocation extends Model

public function molecules()
{
return $this->belongsToMany(Molecule::class)->withTimestamps();
return $this->belongsToMany(Molecule::class)->withPivot('locations')->withTimestamps();
}
}
4 changes: 2 additions & 2 deletions app/Models/Molecule.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public function collections(): BelongsToMany

public function organisms()
{
return $this->belongsToMany(Organism::class)->withTimestamps();
return $this->belongsToMany(Organism::class)->withPivot('id','organism_parts')->withTimestamps();
}

public function geoLocations()
{
return $this->belongsToMany(GeoLocation::class)->withTimestamps();
return $this->belongsToMany(GeoLocation::class)->withPivot('locations')->withTimestamps();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Organism.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class Organism extends Model

public function molecules()
{
return $this->belongsToMany(Molecule::class)->withTimestamps();
return $this->belongsToMany(Molecule::class)->withPivot('id','organism_parts')->withTimestamps();
}
}

0 comments on commit c51050c

Please sign in to comment.