-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control over created models/attached fields #2506
Comments
You can use Observers. |
|
Does using the public function fields() {
return [
BelongsToMany('Example')->fields([
Text::make('Weight')->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
// Fill pivot fields here
})
]),
];
} |
It kinda is, but it isn't documented at all. On a sidenote, I haven't found the new Hidden field documented either. This method would be ok for using the model/request to derive the data, but what if I want to fill more fields that are not part of this, eg. user_id. Let's say it's not a field I can show to the user because it's a secret, would I just go with Hidden field filling the value somehow to empty so the value doesn't show up for user in code and fillUsing to edit the model? Another question is, if I have first field which gets changed by fillUsing by $model->field = $anotherValue, and another field which needs the old value of the first field, my only hope is to exchange the positioning of these two and probably can cause (in rare ocassions) weird bugs. Am I right? It is possible that my thinking is maybe to deep and that these situations don't happen, just a thought. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
It still is kinda issue, I had to go with third party package which doesn't seem to work well with Nova sometimes. Pivot data observers are still a problem. |
Yes you can grab the current Nova's resources and fields are not designed to manage pivot data. Any effort to do so is a hack outside of what's officially supported at this time. If using Observers or |
So actually I am reacting to this PR https://github.com/laravel/nova/pull/869 where we got the hidden fields, which is great.
Now, it may be a question if there's already a way to do this, or a feature request if it doesn't.
I have several resources that needs additional model fields to be filled.
This is quite easy, just overriding the newModel to fill the required fields which aren't directly controllable by the form.
Now the problem rises when I don't actually know the field value and actually need to derive the value from the request. This might be a bad example, but let's say I add a weight to the ingredient resource. The products resource, that uses this ingredient, needs to update it's total weight based on all of their ingredients.
Also, I have several BelongsToMany fields, which, on attach, needs to add additional data about the attached (pivot) row.
Does this make sense? We don't actually have an (easy) way to modify the fields that are being inserted into the pivot tables.
The text was updated successfully, but these errors were encountered: