How to get record data or just id of a relation manager record.

class ItemsRelationManager extends RelationManager
{
protected static string $relationship = 'items';

protected static ?string $recordTitleAttribute = 'id';

public static function form(Form $form): Form
{

//how to get the record id here
}
}
class ItemsRelationManager extends RelationManager
{
protected static string $relationship = 'items';

protected static ?string $recordTitleAttribute = 'id';

public static function form(Form $form): Form
{

//how to get the record id here
}
}
14 Replies
guitarnerd_
guitarnerd_OP15mo ago
$livewire->ownerRecord is giving me the parent component entire data. I want simply the current record in the recordmanager
toeknee
toeknee15mo ago
$this->record?
guitarnerd_
guitarnerd_OP15mo ago
can't use $this in a static function @toeknee
toeknee
toeknee15mo ago
$livewire->record ?
guitarnerd_
guitarnerd_OP15mo ago
@toeknee gave me that the property doesn't exist Anyone ?:(
awcodes
awcodes15mo ago
what are you trying to do, it doesn't make sense to use the record id in the form definition?
thiktak
thiktak15mo ago
Depending where you need it 🙂 Inside some function, you can use $this->record
public function getTitle(): string
{
return __('Answers of') . ' ' . ($this->record ?? '');
}
public function getTitle(): string
{
return __('Answers of') . ' ' . ($this->record ?? '');
}
Inside table() : (you can check for form, should have something similar)
$table->getLivewire()->getOwnerRecord();
$table->getLivewire()->getOwnerRecord();
Inside form(), you can also use a function 🙂
public static function form(Form $form): Form
{
return $form->schema(function(...) {
return [ // add you schema here, and access to data
];
});
}
public static function form(Form $form): Form
{
return $form->schema(function(...) {
return [ // add you schema here, and access to data
];
});
}
Just need to found the object that can provide the record 🙂 (Livewire ? Component ? etc ..)
guitarnerd_
guitarnerd_OP15mo ago
@awcodes Thank you for your answer. I have an OrdersResource. Inside orders resource I have a RelationManager table containing the OrderItems. When the user clicks on an Order Item the form opens. Inside the form I want to have a table, using ViewField containing all the Quotes that can fulfill that OrderItem with an action button that awards that order to that quote. I need it in the form inside a RelationManager.
class ItemsRelationManager extends RelationManager
{
protected static string $relationship = 'items';

protected static ?string $recordTitleAttribute = 'id';

public static function form(Form $form): Form
{
return $form
->schema(
function (RelationManager $livewire): array {
dd($livewire->ownerRecord);
....
}
}
class ItemsRelationManager extends RelationManager
{
protected static string $relationship = 'items';

protected static ?string $recordTitleAttribute = 'id';

public static function form(Form $form): Form
{
return $form
->schema(
function (RelationManager $livewire): array {
dd($livewire->ownerRecord);
....
}
}
ownerRecord gives me the data of the parent not the relation manager record
thiktak
thiktak15mo ago
On all OrderLines, you created a custom action to open the creation form ?
guitarnerd_
guitarnerd_OP15mo ago
@awcodes Thank you. I'm using v2 and I managed to get it inside the view through the only place I managed to get it is inside the ViewField component using
{{ $evaluate(fn ($get) => $get('id')) }}
{{ $evaluate(fn ($get) => $get('id')) }}
but I was hoping I can get it in my RelationManager to query a model and pass the results to the view
awcodes
awcodes15mo ago
could try $form->getRecord(). not sure if that was in v2 or not. Still feels like you're doing something the wrong way here. But i'm not totally sure.
thiktak
thiktak15mo ago
Just tested. I added a createAction on my User model -> relation to teams (belongsToMany).
->actions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\CreateAction::make(),
])
On my form, I have access to the model & the pivot
public function form(Form $form): Form
{
dd($form->getRecord()); // access to pivot and then data
}
public function form(Form $form): Form
{
dd($form->getRecord()); // access to pivot and then data
}
Then, I know the record & the line selected. If id is needed, add it on the withPivot
No description
guitarnerd_
guitarnerd_OP15mo ago
Thank you i'll check those answers hi! Is $table->getLivewire() in v2? it's not working for me Thanks everyone! I ended up rethinking how i'm doing it and opting for a different architecture
Want results from more Discord servers?
Add your server