save repeater data in pivot table

I have purchases table where will be many brands with amount and im using repeater for form. so for that i decide to make pivot table to save brand id and brand amount in another pivote table. i cant find same example or solution.. how its be good to do?
4 Replies
gigiloouu
gigiloouuOP10mo ago
like i have this inside the purchase model
public function purchasePivot(): HasMany
{
return $this->hasMany(PurchasePivot::class);
}
public function purchasePivot(): HasMany
{
return $this->hasMany(PurchasePivot::class);
}
and also repeater looks like this
Repeater::make('purchasePivot')
->relationship()
->schema([
Select::make('brand_id')
->label('Brand')
->relationship('brand', 'name', function (Builder $query, Get $get) {
if($get('../../supplier_id') === null) {
return;
}
$brandIds = Supplier::find($get('../../supplier_id'))->brand_id;
$query->whereIn('id', $brandIds);
})
->searchable()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->required()
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Brand'),
TextInput::make('brand_amount')
->numeric()
->required()
]),
TextInput::make('amount')->required()
->required(),
])
->columns(2)
->addActionLabel('დაამატე ბლოგი')
->collapsible(),
Repeater::make('purchasePivot')
->relationship()
->schema([
Select::make('brand_id')
->label('Brand')
->relationship('brand', 'name', function (Builder $query, Get $get) {
if($get('../../supplier_id') === null) {
return;
}
$brandIds = Supplier::find($get('../../supplier_id'))->brand_id;
$query->whereIn('id', $brandIds);
})
->searchable()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->required()
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Brand'),
TextInput::make('brand_amount')
->numeric()
->required()
]),
TextInput::make('amount')->required()
->required(),
])
->columns(2)
->addActionLabel('დაამატე ბლოგი')
->collapsible(),
and where i should create pivot class? idk i try many way just everytime i get silly things.. thats means im not doing right way any ideas?
Hasith
Hasith10mo ago
Read this carefully. You need to create new model for the pivot table and use that relationship name for the repeater. Follow step by step according to your needs.
gigiloouu
gigiloouuOP10mo ago
yep i did it alrready thanks when i read carefully its worked d
Want results from more Discord servers?
Add your server