如何在octobercms中创建依赖性droppdown

问题描述 投票:0回答:1

我的模型是“术语”和“位置”。期限取决于位置。每个位置都有4个不同的start_dates和finish_dates。

有人可以帮我这个吗?

octobercms octobercms-plugins octobercms-backend
1个回答
1
投票

在字段定义中:

location_id:
    label: Location
    type: dropdown

term_id:
    label: Term
    type: dropdown
    dependsOn: location

然后,在控制器中:

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');
}

有关更多信息:OctoberCMS Documentation

© www.soinside.com 2019 - 2024. All rights reserved.