Updating from 3.2.83 to 3.2.84 break custom component

So we have a custom component that stopped working between these 2 version. I've attached the Resource and Component: https://gist.github.com/mrleblanc101/714180585a24a82383f8fbd5b0e5dccd
Gist
PracticeMatrix.php
GitHub Gist: instantly share code, notes, and snippets.
No description
26 Replies
mrleblanc101
mrleblanc1013mo ago
If I edit the data in phpMyAdmin directly, the data is show correcly in the component, so only the save is not working.
mrleblanc101
mrleblanc1013mo ago
If I revert t 3.2.83 everything works as you can see
No description
mrleblanc101
mrleblanc1013mo ago
I've isolated the issue to this change (L228), any idea what is happening ?
No description
mrleblanc101
mrleblanc1013mo ago
Anyone has an idea ?
awcodes
awcodes3mo ago
Can you update to 3.2.102? It’s the latest so you’re a little behind. Possibly 84 had a bug that has been fixed.
mrleblanc101
mrleblanc1013mo ago
Yes I did try, it doesn't work either. That's because of the change I showed in the screenshot above, there has been to other change to that file since patch 84
awcodes
awcodes3mo ago
Does it work on create?
mrleblanc101
mrleblanc1013mo ago
The field is hidden on create, I'd have to try but I'm out and I don't have my laptop with me (just my phone)
awcodes
awcodes3mo ago
No worries. I’m on my phone too. No hurry.
mrleblanc101
mrleblanc1013mo ago
If I add line 228 back by editing the source in vendor, it works again
awcodes
awcodes3mo ago
Nothing is standing out to me about your code that wouldn’t work. But I would also expect other reports if it was a bug.
mrleblanc101
mrleblanc1013mo ago
I think must be related to the pivot
awcodes
awcodes3mo ago
Where is the relationship? Not seeing it in the gist? I would start debugging in the getPracticeData() method. Make sure you are getting the right state to start with during hydration and dehydration.
mrleblanc101
mrleblanc1013mo ago
I think the state is ok, because everything is fine if I edit in phpMyAdmin. Just the save that doesn't work anymore
awcodes
awcodes3mo ago
Which tells me something could be going wrong during the dehydration. Again, though, I don’t see any relationship on the field so not sure where or how you are saving that.
mrleblanc101
mrleblanc1013mo ago
I'll try to provide more data once I get home, this is on a private Gitlab instance so I can't share easily
awcodes
awcodes3mo ago
No worries.
mrleblanc101
mrleblanc1013mo ago
On the Product resource I have this:
protected $fillable = [
'name',
'slug',
'notes',
'team_id',
'client_id',
'state',
'leads'
];

...

public function practices(): BelongsToMany
{
return $this->belongsToMany(Practice::class, 'product_practice')
->withPivot('notes', 'state');
}

...
protected $fillable = [
'name',
'slug',
'notes',
'team_id',
'client_id',
'state',
'leads'
];

...

public function practices(): BelongsToMany
{
return $this->belongsToMany(Practice::class, 'product_practice')
->withPivot('notes', 'state');
}

...
awcodes
awcodes3mo ago
Any particular reason for not just using the ->relationship() method and letting filament just handle it. Are you overriding the save or mutate methods on the EditProduct page?
mrleblanc101
mrleblanc1013mo ago
I don't know what you mean. I'm pretty new to Filament I don't think so. Do you mean in the Filament resource ? No
awcodes
awcodes3mo ago
What is in Filament\Resources\Product\Pages\EditProduct.php in your app.
mrleblanc101
mrleblanc1013mo ago
Oh god, I didn't even know about those file lol. I'm sorry as I said I'm not the one that made that code, only trying to debug why the update broke it There is that:
protected function beforeSave()
{
$hook = App::make(HookProduct::class);
$hook->onProductSave($this->data['id']);
$product = Product::find($this->data['id']);
$practiceToSave = [];
foreach ($this->data['practice_matrix'] as $practice) {
$practiceToSave[$practice['id']] = [
'state' => $practice['state'] ?: 'no',
'notes' => $practice['notes'],
'practice_id' => $practice['id'],
'product_id' => $this->data['id'],
];
}
$product->practices()->sync($practiceToSave);
}
protected function beforeSave()
{
$hook = App::make(HookProduct::class);
$hook->onProductSave($this->data['id']);
$product = Product::find($this->data['id']);
$practiceToSave = [];
foreach ($this->data['practice_matrix'] as $practice) {
$practiceToSave[$practice['id']] = [
'state' => $practice['state'] ?: 'no',
'notes' => $practice['notes'],
'practice_id' => $practice['id'],
'product_id' => $this->data['id'],
];
}
$product->practices()->sync($practiceToSave);
}
Might be a good place to debug next
awcodes
awcodes3mo ago
Hmm. Yea. Something could definitely be going wrong there.
mrleblanc101
mrleblanc1013mo ago
Yeah I'll put some dd() and check what is happening Honestly I thought everything was handled by Filament directly Since I couldn't find where the save was happening
awcodes
awcodes3mo ago
It typically would be if the relationship was setup and implemented correctly, but there’s times when you need to be explicit. Just don’t know enough about the app to know if it’s needed or not.
mrleblanc101
mrleblanc1013mo ago
I think the goal was being able to edit all the row of the relationship (and the 2 pivot fields) directly, but maybe that possible natively ? We are coming from Laravel Nova where this wasn't possible. @awcodes I think i got it be removing the beforeStateDehydrated. I have no idea what purpose it served, I can't even find documentation about this function in the doc. I guess 3.2.84 fixed a bug where the beforeStateDehydrated was not called, but we didn't need it in the first place ? 🤷‍♂️ Thanks for your help !
protected function setUp(): void
{
parent::setUp();

$this->afterStateHydrated(static function ($record, PracticeMatrix $component, $state) {
if ($record) {
$practiceData = self::getPracticeData($record->id);
$component->practicesData($practiceData);
$component->state($practiceData);
}
});
// $this->beforeStateDehydrated(static function ($record, PracticeMatrix $component, $state) {
// if ($record) {
// $practiceData = self::getPracticeData($record->id);
// $component->practicesData($practiceData);
// $component->state($practiceData);
// }
// });
}
protected function setUp(): void
{
parent::setUp();

$this->afterStateHydrated(static function ($record, PracticeMatrix $component, $state) {
if ($record) {
$practiceData = self::getPracticeData($record->id);
$component->practicesData($practiceData);
$component->state($practiceData);
}
});
// $this->beforeStateDehydrated(static function ($record, PracticeMatrix $component, $state) {
// if ($record) {
// $practiceData = self::getPracticeData($record->id);
// $component->practicesData($practiceData);
// $component->state($practiceData);
// }
// });
}
Want results from more Discord servers?
Add your server