0

My models are "term" and "location". Term depends on Location. Each location has 4 term wih different start_dates and finish_dates.

Can anyone help me with this please?

Dapk
  • 203
  • 2
  • 10
  • have you checked this one my be it can help you : https://octobercms.com/forum/post/dropdown-options-dependent-on-selected-value-on-other-dropdown and https://gateway.octobercms.com/docs/backend/forms#field-dependencies – Hardik Satasiya Mar 20 '19 at 09:58

1 Answers1

1

In the fields definition:

location_id:
    label: Location
    type: dropdown

term_id:
    label: Term
    type: dropdown
    dependsOn: location

Then, in the controller:

public function getLocationOptions()
{
    // this will return an array of Location names indexed by id
    return Location::pluck('name', 'id);
}

public function getTermOptions()
{
    return Term::where('location_id', $this->location_id)->pluck('name', 'id');
}

For more information: OctoberCMS Documentation

Nelson Otazo
  • 119
  • 6