This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello, I need to validate a pivot column, that depends on other column in related model .
The Plugin manage Features (like attributes, etc), the model have a boolean column name has_value
. A second plugin (named Catalog
), that depends on Features
, has a table product_features
with columns product_id
, feature_id
and value
(this is the pivot column). I need to validate the pivot column if the Feature.has_value is true.
I could do this, in controller using this method:
public function update_onRelationManagePivotCreate() {
if(post('_relation_field') == 'features') {
$featureId = post('foreign_id');
if($feature = Feature::find($featureId)) {
if($feature->has_value && !post('Feature.pivot.value')) {
Flash::error(Lang::get('validation.required', ['attribute' => Lang::get('planetadeleste.catalog::lang.fields.value') ]));
return $this->onRelationManagePivotForm();
}
}
}
return parent::onRelationManagePivotCreate();
}
At this point, the validation works fine. But, when prompt the flash alert message, the modal window was not opened again. I know it is possible to re open the pivot modal window. but I don't know how.
Sorry about my english. I hope to be clear ;)
thanks
A little late, but meybe someone find this useful.
You should create pivot model like in this video.
Than in this model you can add validation trait and validation rules like you used to validate october model.
The current problem is after validation, the popup will close and there will be only validation message. I created a PR to correct this bug. Likely it will be fixed in next build.
Last updated
1-2 of 2