В моем приложении Laravel -5.8 я пытаюсь разработать jQuery -fullcalendar для выхода из приложения
Controller:
public function index()
{
try {
$userCompany = Auth::user()->company_id;
$userID = Auth::user()->id;
$userEmployee = Auth::user()->employee_id;
$render=[];
$leavetypes = HrLeaveType::where('company_id', $userCompany)->get();
$leaverequests = HrLeaveRequest::where('employee_id', $userEmployee)->where('company_id', $userCompany)->whereYear('created_at', date('Y'));
$leaverequests=$leaverequests->with('leavetype');
if(isset($request->leave_type_id))
{
$leaverequests=$leaverequests->where('leave_type_id',$request->leave_type_id);
$render['leave_type_id']=$request->leave_type_id;
}
$leaverequests= $leaverequests->paginate();
$leaverequests= $leaverequests->appends($render);
$data['leaverequests'] = $leaverequests;
$data['leavetypes']= HrLeaveType::where('company_id', $userCompany)->pluck('leave_type_name','id');
return view('service.leave_requests.index',$data);
} catch (Exception $exception) {
Session::flash('error', 'Action failed! Please try again');
return back();
}
}
Полный календарь jQuery работает должным образом. Но у меня проблема с фильтром / поиском.
index.blade
<div class="card-body p-0">
<div id='calendar'></div>
</div>
@section('javascript')
<script>
$(document).ready(function () {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
// put your options and callbacks here
header: {
left: 'prev,next,today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
events : [
@foreach($leaverequests as $leaverequest)
{
title : '{{ $leaverequest->leavetype->leave_type_name }}',
fullname : '{{ $leaverequest->employee->first_name . ' ' . $leaverequest->employee->last_name }}',
start : '{{ Carbon\Carbon::parse($leaverequest->commencement_date)->format('d-m-Y') ?? '' }}',
end: '{{ Carbon\Carbon::parse($leaverequest->resumption_date)->format('d-m-Y') ?? '' }}',
url : '{{ route('service.leave_requests.edit', $leaverequest->id) }}'
},
@endforeach
]
})
});
</script>
@stop
Я написал это для фильтра, поэтому ищите по типу left_type.
<div class="card-body">
{{ Form::model(request(),['method'=>'get']) }}
<div class="row" style="margin-bottom: 10px">
<div class="col-sm-4">
{{Form::label('leave_type_id', 'Leave Type:')}}
{{ Form::select('leave_type_id',$leavetypes,null,['class'=>'form-control select2bs4','placeholder'=>'Select Leave Type']) }}
</div>
<div class="col-sm-3">
<br>
{{ Form::submit('Filter',['class'=>'btn btn-primary']) }}
</div>
{{ Form::close() }}
</div>
</div>
Когда я нажимаю на фильтр, он не работает. Как заставить фильтр работать?
Спасибо.