У меня есть Laravel -5.8 функция контроллера:
public function findLeaveCount(Request $request)
{
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$userId = Auth::user()->id;
$employeeemptypeid = DB::table('hr_employees')->select('employment_type_id')->where('id', $userId)->first()->employment_type_id;
$leavetypeid = DB::table('hr_leave_types')->select('id')->where('company_id', $userCompany)->where('id',$request->id)->first()->id;
$authorizedleavedays = 0;
$authorizedleavedays = DB::table('hr_leave_type_details')->select('no_of_days')->where('leave_type_id', $leavetypeid)->where('employment_type_id',$employeeemptypeid)->first();
$availableleavedays = 0;
$availableleavedays = DB::table('hr_leave_requests')->select(DB::raw("IFNULL(SUM(no_of_days),0) as no_of_days"))->where('employee_id', $userEmployee)->where('leave_type_id', $request->id)->whereYear('created_at', '=', date('Y'))->first();
return response()->json([
'authorizedleavedays' => $authorizedleavedays->no_of_days,
'availableleavedays' => $availableleavedays->no_of_days,
]);
}
route / web. php
Route::get('get/findLeaveCount','Service\ServiceLeaveRequestsController@findLeaveCount')->name('get.leavecounts.all');
view: create.blade
<div class="col-sm-4">
<div class="form-group">
<label>Leave Type:<span style="color:red;">*</span></label>
<select id="leave_type" class="form-control select2bs4" data-placeholder="Choose Leave Type" tabindex="1" name="leave_type_id" style="width: 100%;">
<option value="">Select Leave Type</option>
@if($leavetypes->count() > 0)
@foreach($leavetypes as $leavetype)
<option value="{{$leavetype->id}}">{{$leavetype->leave_type_name}}</option>
@endforeach
@endif
</select>
</div>
</div>
<input type="hidden" id="available_leave_daysx" class="form-control" value="0" >
<div class="col-sm-4">
<div class="form-group">
<label>Authorized Leave Days:</label>
<input id="authorized_leave_days" type="number" class="form-control" value="0" style="width: 100%;" disabled>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Available Leave Days:</label>
<input id="available_leave_days" type="number" class="form-control" value="0" style="width: 100%;" disabled>
</div>
</div>
Когда
<select id="leave_type" class="form-control select2bs4" data-placeholder="Choose Leave Type" tabindex="1" name="leave_type_id" style="width: 100%;">>
находится на замене, он должен выполнить эту функцию:
<script type="text/javascript">
$(document).ready(function() {
$(document).on('change', '#leave_type', function() {
var air_id = $(this).val();
var a = $(this).parent();
// console.log("Its Change !");
var op = "";
$.ajax({
type: 'get',
url: '{{ route('get.leavecounts.all') }}',
data: { 'id': air_id },
dataType: 'json', //return data will be json
success: function(data) {
console.log(data.authorizedleavedays);
console.log(data.availableleavedays);
$('#authorized_leave_days').val(data.authorizedleavedays);
$('#available_leave_daysx').val(data.availableleavedays);
let authorizedLeaveDays = $('#authorized_leave_days').val(data.authorizedleavedays);
let availableLeaveDays = $('#available_leave_daysx').val(data.availableleavedays);
let sumAvailableDays = parseInt(authorizedLeaveDays) - parseInt(availableLeaveDays);
#available_leave_days = sumAvailableDays
},
error:function(){
}
});
});
});
</script>
Но я получил эту ошибку:
Uncaught SyntaxError: Неожиданный идентификатор
Когда я нажимаю на него, эта строка кода выделяется:
available_leave_days = sumAvailableDays;
Как решить это?
спасибо