This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

adnan.pri11346
adnan.pri11346

I have 2 belongsTo relationships for a model in a form. merchant and store. store belongsTo merchant as well.

    merchant:
        label: Merchant
        type: relation
        nameFrom: name
        span: left

    store:
        label: Store
        type: dropdown
        dependsOn: merchant
        span: left

When merchant changes, I want the store dropdown to be populated with the stores belonging to merchant. Here's my PHP:

    public function getStoreOptions()
    {
         return Store::whereMerchantId($this->merchant_id)->lists('name', 'id');
    }

When I first open the form it seems to load fine. When I change merchant I'm getting a 500 error. A POST request goes to the update route and I get a mass assignment error as if it's trying to save the model. What am I doing wrong?

Thanks in advance.

adnan.pri11346
adnan.pri11346

Backend\Widgets\Form::setFormValues has a $this->model->fill($data); for some reason. I had to comment that out.

Mohsin
Mohsin

Try digging thro’ the code of location plugin. It does something like what you asked for i.e. when you change the country the dropdown changes the list of states belonging to the selected country.

Last updated

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.