Last active
May 10, 2017 08:00
-
-
Save talha08/fec67fa2e72e0810d9e7e759fecd12f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApiController extends Controller | |
| { | |
| /** | |
| * Section dependant dropdown system | |
| * This is for committee create | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function sectionDropDownData() | |
| { | |
| $member_type_id = \Input::get('member_type_id'); | |
| if($member_type_id == 1 or $member_type_id == 2 ){ | |
| $teacherList =\DB::table('role_user') | |
| ->where('role_id',2) | |
| ->lists('user_id'); | |
| $users = User::where('dept_id', \Auth::user()->dept_id)->whereIn('id',$teacherList )->lists('name','id'); | |
| return \Response::json($users); | |
| }else{ | |
| $studentList =\DB::table('role_user') | |
| ->where('role_id',3) | |
| ->lists('user_id'); | |
| $users = User::where('dept_id', \Auth::user()->dept_id)->whereIn('id',$studentList )->lists('name','id'); | |
| return \Response::json($users); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Api route | |
| Route::get('api/section-dropdown', array('as' => 'apiroute', 'uses' => 'ApiController@sectionDropDownData')); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {!! Form::open(array('route' => 'student.search')) !!} | |
| <div class="form-group"> | |
| {!! Form::label('class_id', 'Select Class :', array('class' => 'control-label')) !!} | |
| {!!Form::select('class_id', $class, '',array('class' => 'select2', 'autofocus','id'=>'class'))!!} | |
| {!! Form::label('section_id', 'Select Section :', array('class' => 'control-label')) !!} | |
| {!!Form::select('section_id', $section, '',array('class' => 'select2', 'autofocus', 'id'=>'section'))!!} | |
| {!! Form::submit('Search', array('class' => ' btn btn-primary')) !!} | |
| </div><br/> | |
| {!! Form::close() !!} | |
| <script type="text/javascript" charset="utf-8"> | |
| //depandable dropdown start | |
| $('#type').on('change', function(e){ | |
| var member_type_id = e.target.value; | |
| //ajax | |
| var path = "<?php echo URL::route('apiroute'); ?>"; | |
| $.get(path+'?member_type_id='+member_type_id, function(data){ | |
| //success data | |
| $('#user').empty(); | |
| $('#user').append('<option value=""> Please choose one</option>'); | |
| $.each(data, function(key, value) { | |
| var option = $("<option></option>") | |
| .attr("value", key) | |
| .text(value); | |
| $('#user').append(option); | |
| }); | |
| }); | |
| }); | |
| //depandable dropdown end | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment