InlineRepeater deleting data on related Model entries

I'm using an InlineRepeater to add relations with pivot data between two Repositories. The relations and pivot data are being stored as expected, but I just realized that when I update the entry, it is also deleting Media and Block data for the related model entry. I just lost a good bit of work to this. I have a repository Location and a repository Taxa, with a location_taxa many-to-many pivot table to connect the two. In the Taxa model, I've created this relation:
public function locations(): BelongsToMany
{
return $this->belongsToMany(Location::class)
->orderByPivot('position')
->withPivot(['details']);
}
public function locations(): BelongsToMany
{
return $this->belongsToMany(Location::class)
->orderByPivot('position')
->withPivot(['details']);
}
In my TaxaController, I've configured the InlineRepeater as such:
Fieldset::make()->title('Locations')->id('locations')->fields([
InlineRepeater::make()
->name('location_taxa')
->label('Locations')
->allowBrowser()
->relation(Location::class)
->fields([
Input::make()
->name('title')
->translatable()
->disabled(),

Wysiwyg::make()
->name('details')
->translatable()
,

]),
]),
);
Fieldset::make()->title('Locations')->id('locations')->fields([
InlineRepeater::make()
->name('location_taxa')
->label('Locations')
->allowBrowser()
->relation(Location::class)
->fields([
Input::make()
->name('title')
->translatable()
->disabled(),

Wysiwyg::make()
->name('details')
->translatable()
,

]),
]),
);
This stores the relationship and details in the pivot table as expected. I'm not sure why it's also accidentally destroying the data
daniel
daniel101d ago
This is a pretty devastating blocker for this project and so any help is greatly appreciated.
daniel
daniel101d ago
Looking at the payload from saving the Taxa, I can only guess it's because the blocks and medias fields are empty here, but I don't know how I would go about changing this behavior. Why is it sending/saving more than just the pivot field(s)?
No description
ifox
ifox101d ago
Hey @daniel Twill 3.1 is out now so I'll try to spend more time to help here. Any chance you could provide a quick repro for this? That'll help expedite getting the support you need if you can Maybe that's not needed after reviewing everything you shared I see what's going on
daniel
daniel99d ago
Ok great @ifox any more thoughts on this one?
ifox
ifox99d ago
@daniel you're using updateRepeaterWithPivot, right?
daniel
daniel99d ago
@ifox yeah, updateRepeaterWithPivot and getFormFieldForRepeaterWithPivot
No description
No description
ifox
ifox99d ago
ok, so our implementation has only been used for simple related models where all the fields from that model would be in the repeater (not just the title like you have). As in, the associated content is created inline and the related module isn't exposed standalone in the CMS where it could have medias and blocks etc... since you only ever want to update the pivot fields can you try to comment out this line https://github.com/area17/twill/blob/063b4bbbe2b133f48008de250be8f767ce2350c1/src/Repositories/Behaviors/HandleRepeaters.php#L219? If that works you can override the function in your project for now and we could just add an option or another method to achieve your use case. It makes a lot of sense to me, we just haven't structured our form that way
GitHub
twill/src/Repositories/Behaviors/HandleRepeaters.php at 063b4bbbe2b...
Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/c...
ifox
ifox99d ago
To clarify, the inline repeater as it is currently implemented is meant to write into the related model too (hence inline), not just the pivot but we can easily add what you need to only edit the pivot
daniel
daniel95d ago
this worked! thank you so much. just curious -- is there another method that would be more "standard" for my use case? or am I just doing something that hadn't been considered before? either way, really glad that there's a workaround for it. eventual official support would of course be awesome. thank you again!
ifox
ifox95d ago
Awesome, yeah it's just that it hasn't been considered It will! And I'll let you know when you can remove your override
Want results from more Discord servers?
Add your server
More Posts
"astrotomic/laravel-translatable" n+1 queriesI've got a package issue which is composer required by twill. 800+ queries on a model only getting Repeaters and Blockeditor won't work with media library.I saw the pst regarding JSON repeaters. So I switched to the block editor for the content that NEEDSTag Field on Block not Displaying Saved TagsHello. I am using the Tag Field in a block, the tags are being saved correctly, but the field is cFile link in view issueHi everyone i'm trying to render a file in blade view bug seem difficult to me how can i render linIssue using repository methods??? Twill 3Can someone please provide any support for the following error: Declaration of App\Repositories\PostHow can I make sure my assets are loaded correctly on a subdomain?I have a site for example website.nl and a twill installation on website.nl/subsite Now when I go tI can't see any images in twill media library.Hello, everyone! I have installed twill and tried to upload a image to media library. However, I amDatePicker ExceptionI'm getting an unexpected error while using a pretty simple DatePicker in my sidebar form. `UndefinSome fresh vibes would be nice :))Would love to hear some global announcement about twill cms this year and where it's heading @ifox .Edit defaultOrders in controllerWhat would be the most correct way to edit? $this->defaultOrders of ModuleController in my controlleVue2 EOL Plans?We're upgrading our application and generally upgrading our setup in preparation for the Vue2 EOL atRoute [admin.password.reset.link] not defined on upgrade from 2.x to 3Hey folks, I followed the upgrade guide step by step successfully, but when I try to visit the adminTwicpics & fit=cropApparently fit=crop is automatically added to the url, also when using Twicpics as image service. HoCan anyone help me get a single image/media field working within a json repeater ?I've detailed the issue here: https://github.com/area17/twill/discussions/2358DatePicker problemHi! sorry, what s wrong with my setup .... Just installed a fresh laravel app, with newest twill 3Admin api requests blocked for mixed-contentThis is an odd one and happening in a single environment (which unfortunately is production) . I knoI'm lookig for the DNS Settings of my website. Can anybody help me please?The person who made my website is not available and i need to access my dns settings. Thanks!How to load images in smaller size while keeping aspect ratio and not cutting parts of it off?Hello, I am trying display images with a smaller width that I uploaded in my CMS but without any cr419 login superadminHi all, I'm deploying a project with docker containers, I created a superadmin, I try to log in and Call to a member function permissions() on stringCan you give me a hint, please? In config/twill.php I specified return [ 'enabled' => [ 'per