I have created two plugins (States and Suburbs) using Builder plugin and so far it works great.
The Thing is, in States plugin, I am simply allowing ability to add state names and in Suburbs plugin, I am allowing users to select State first and then enter suburb name. All works fine as of now in these two plugins.
Now the thing is, I have a third plugin called as Properties in which I have both these 2 drop-downs State and Suburb but as of now All States and All Suburbs are showing. But I want users to select first State and then based on state selection it should should all its suburbs to my another Suburb drop-down.
I have tried to use dependsOn which Builder plugin provides but I just am not able to understand the flow to achieve it step by step based on the current scenario I have. Below is the code what I have done and tried so far.
plugins\technobrave\properties\models\Property.php
<?php namespace Technobrave\Properties\Models;
use Model;
use technobrave\states\Models\State as State;
use technobrave\suburbs\Models\Suburb as Suburb;
public function getStateIdOptions()
{
// getting all states
$get_all_states = State::all();
$fields[''] = 'Select any State';
foreach ($get_all_states as $current_state) {
$fields[$current_state->attributes['id']] = $current_state->attributes['state_name'];
}
ksort($fields);
return $fields;
}
public function getSuburbIdOptions($stateId)
{
// getting all suburbs
$get_all_suburbs = Suburb::all();
$fields[''] = 'Select any Suburb';
foreach ($get_all_suburbs as $current_suburb) {
$fields[$current_suburb->attributes['id']] = $current_suburb->attributes['suburb'];
}
ksort($fields);
return $fields;
}
}
How can I do this from here on ? Any help or guidance will be highly appreciated and useful.
Thanks