Closed XbNz closed 1 year ago
Hey @XbNz! We're sorry to hear that you've hit this issue. 💛
However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue?
We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly.
Ok, some more info:
Whatever is happening inside of Livewire\Features\SupportValidation\HandlesValidation::validate()
is causing the issue. In particular, this specific code snippet:
$data = $this->prepareForValidation(
$this->getDataForValidation($rules)
);
Which seems to be turning my $rules
into, well, whatever this is...
$data: array:11 [▼ // vendor/livewire/livewire/src/Features/SupportValidation/HandlesValidation.php:210 "record" => null "data" => [] "previousUrl" => "http://app.test/admin/resource-name/create" "mountedActions" => [] "mountedActionsArguments" => [] "mountedActionsData" => [] "componentFileAttachments" => [] "mountedFormComponentActions" => [] "mountedFormComponentActionsArguments" => [] "mountedFormComponentActionsData" => [] "mountedFormComponentActionsComponents" => [] ]
And then trying to compare it to the $rules
, using:
$this->checkRuleMatchesProperty($rules, $data);
protected function checkRuleMatchesProperty($rules, $data)
{
collect($rules)
->keys()
->each(function($ruleKey) use ($data) {
throw_unless(
array_key_exists(Utils::beforeFirstDot($ruleKey), $data),
new \Exception('No property found for validation: ['.$ruleKey.']')
);
});
}
And that's where the error is thrown.
Could it be that for every rule key, livewire expects a corresponding public property?
I also face the same issue.
I had this problem as well. It appears to be an undocumented, massive breaking change.
The way I fixed it was as follows (please leave a heart or thumbs up if you were affected and this helps - if this is a recurring issue I'll file a PR to add it to breaking changes):
public ?array $data = [];
use Filament\Forms;
public function form(Forms\Form $form): Forms\Form
{
return $form
->schema($this->getFormSchema())
->statePath('data');
}
I noticed this because if you read the new, v3 documentation for adding a form to a Livewire component, getFormSchema()
never appears anymore. Yet it still functions in apparently (I'm just guessing) a botched attempt at backwards compatibility which in some situations backfires and just makes things confusing.
Edit: Also, for fixing broken relationships: https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#setting-a-form-model
@gjsman Thank you so much for your valuable comment.
@gjsman Thanks man! Just came back to post that I solved it reading this -> https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component
@gjsman it worked
@gjsman it worked
Package
filament/filament
Package Version
v3.0.30
Laravel Version
v10.20.0
Livewire Version
v3.0.0-beta.10
PHP Version
PHP 8.2.8
Problem description
The error is not very clear, in fact, the end of the stack trace is inside
index.php
which is never helpful.Did some digging and found
Livewire\Features\SupportValidation\HandlesValidation::checkRuleMatchesProperty()
to be at fault.Possibly useful debug info:
Dump results:
array:3 [▼ // vendor/filament/forms/src/Concerns/CanBeValidated.php:78 "field_1" => array:1 [▶] "field_2" => array:3 [▶] "field_3" => array:3 [▶] ]
array:3 [▼ // vendor/filament/forms/src/Concerns/CanBeValidated.php:78 "field_1" => "field 1" "field_2" => "field 2" "field_3" => "field 3" ]
Expected behavior
Work, I guess?
Steps to reproduce
Upgrade from Filament v2 & Livewire v2 to Filament v3 & Livewire v3
Reproduction repository
Unable to reproduce in fresh project
Relevant log output
No response