setDependentRelation(string $fieldName, string $dependencyFromField, string $fieldNameRelation)
Available from version >= 2.6.1

There are cases that dropdown list that was built from setRelation has dependencies between them. The most common example that we see very often on registration forms is that the continent dropdown will filter the countries and countries dropdown will filter the cities.

You can see an example of the expected results here:

Depended Relation Animated

The usage is coming with an extra line of code that is looking like this:

$crud->setDependentRelation('relationFieldName', 'dependencyFieldName', 'parentId')

So for example if we have a country setRelation and a city setRelation that looks like this:


If the city_id is depended (filterted) from country_id then we will need to add only one extra line that will look like this:


With this line of code the result will be that when the country changes then it filters the city_id dropdown will have filtered only the ones from this country.

You can see a full example below:

$crud->setSubject('Customer', 'Customers');

$crud->displayAs('continent_id', 'Continent');
$crud->displayAs('country_id', 'Country');
$crud->displayAs('city_id', 'City');



$output = $output->render();

In case you would like to see the results of the above example we do have the data copied here: