I want to make a role permission based view where there is a dropdown and a list of check box.But when a user choose a role from dropdown corresponding permission should be checked with with that and other will be remain unchecked. For that i used the following View :
<div class="form-group">
<label for="">Roles</label>
<select class="form-control input-sm" name="role_id" id="role_id">
<option selected="selected" style=" display: none;">Choose a Role</option>
@foreach($roles as $role)
<option value=""></option>
@endforeach
</select>
</div>
@foreach($permissions as $permission)
<div class="checkbox">
<label><input type="checkbox" value=""></label>
</div>
@endforeach
Here is the ajax part
$('#role_id').on('change',function(e){
var role_id = $('#role_id option:selected').attr('value');
var info=$.get("",{role_id:role_id});
info.done(function(data){
$.each(data,function(index,subcatObj){
});
});
And here is the route:
Route::get('permission-selected',function(Request $request){
$role_id = $request::input(['role_id']);
$roles=Role::with('permissions')::where('role_id','=',$role_id)->get();
return Response::json($roles);
});
Problem is I couldn't set the checkbox with the dropdown..can anyone suggest one please?
via Hola