Get current form values

How can I get a value from the form to pass to the relationship manager?
public static function getRelations(): array
{
return [
EmployeesRelationManager::make([
'employeeId' => .....,
]),
];
}
public static function getRelations(): array
{
return [
EmployeesRelationManager::make([
'employeeId' => .....,
]),
];
}
Solution:
I have solved it with the mutate and $livewire->getOwnerRecord() ```php <?php ...
Jump to solution
7 Replies
Patrick Boivin
Patrick Boivin14mo ago
I'm curious to know what are you trying to do exactly? Can you share a bit more context?
H.Bilbao
H.BilbaoOP14mo ago
I have a resource that has a Relation Manager that uses the form of another resource. In the relation manager I need one of the main resource values, together with the id that is automatically passed to the relation manager Filament. PRINCIPAL RESOURCE - TICKET RELATIONSHIP MANAGER - TASKS (use TaskResource form) In the relationship manager, the ticket id set by filament, but together with that, I need the customer_id of the ticket.
MRBUG
MRBUG14mo ago
i think this is used for it
$record->team_id
$record->team_id
Patrick Boivin
Patrick Boivin14mo ago
Can you share the code of your relation manager? Just to see how you are reusing the form of the Task resource.
Solution
H.Bilbao
H.Bilbao14mo ago
I have solved it with the mutate and $livewire->getOwnerRecord()
<?php

namespace App\Filament\Resources\TicketResource\RelationManagers;

use App\Filament\Resources\TaskResource;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class TasksRelationManager extends RelationManager
{
public function isReadOnly(): bool
{
return false;
}

protected static string $relationship = 'tasks';

public static function getTitle(Model $ownerRecord, string $pageClass): string
{
return trans('task.resource.label');
}

public function getTablePluralModelLabel(): string
{
return trans('task.resource.label');
}

public function getTableModelLabel(): string
{
return trans('task.resource.single');
}

public function form(Form $form): Form
{
return TaskResource::form($form)
->columns(1);
}

public function table(Table $table): Table
{
return TaskResource::table($table)
->headerActions([
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data, RelationManager $livewire): array {
$data['customer_id'] = $livewire->getOwnerRecord()->customer_id;
return $data;
})
->slideOver(),
])->filters([
Tables\Filters\TernaryFilter::make('is_processed')
->label(trans('task.resource.processed')),
]);
}
}
<?php

namespace App\Filament\Resources\TicketResource\RelationManagers;

use App\Filament\Resources\TaskResource;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class TasksRelationManager extends RelationManager
{
public function isReadOnly(): bool
{
return false;
}

protected static string $relationship = 'tasks';

public static function getTitle(Model $ownerRecord, string $pageClass): string
{
return trans('task.resource.label');
}

public function getTablePluralModelLabel(): string
{
return trans('task.resource.label');
}

public function getTableModelLabel(): string
{
return trans('task.resource.single');
}

public function form(Form $form): Form
{
return TaskResource::form($form)
->columns(1);
}

public function table(Table $table): Table
{
return TaskResource::table($table)
->headerActions([
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data, RelationManager $livewire): array {
$data['customer_id'] = $livewire->getOwnerRecord()->customer_id;
return $data;
})
->slideOver(),
])->filters([
Tables\Filters\TernaryFilter::make('is_processed')
->label(trans('task.resource.processed')),
]);
}
}
Patrick Boivin
Patrick Boivin14mo ago
Nice!
H.Bilbao
H.BilbaoOP14mo ago
Thanks for your time @Patrick Boivin 🙂
Want results from more Discord servers?
Add your server