Laravel-离开日历未显示结果

时间:2020-04-10 19:30:35

标签: laravel

在Laravel-5.8应用程序中,我试图在日历上显示请假请求:

LeaveRequest的模型类如下所示:

class HrLeaveRequest extends Model
{
  public $timestamps = false;
  protected $table = 'hr_leave_requests';
  protected $primaryKey = 'id';

  protected $fillable = [
              'id',
              'company_id',
              'employee_id',
              'reason',
              'leave_type_id',
              'no_of_days',
              'commencement_date',
              'resumption_date',
              'relief_officer_id',
          ];

  protected $casts = [];

  public function company()
  {
    return $this->belongsTo('App\Models\Organization\OrgCompany', 'company_id');
  }

  public function employee()
  {
    return $this->belongsTo('App\Models\Hr\HrEmployee','employee_id');
  } 

  public function reliefofficer()
  {
    return $this->belongsTo('App\Models\Hr\HrEmployee','relief_officer_id');
  }    

  public function leavetype()
  {
    return $this->belongsTo('App\Models\Hr\HrLeaveType','leave_type_id');
  }
}

控制器

public function index(Request $request)
{
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();
        }       
}

视图

<div class="container-fluid">                                    
    <div class="row">
        <div class="col-md-12">
        <!-- general form elements -->
        <!--<div class="card">-->
         <div class="card card-secondary">
            <div class="card-header">
                <h3 class="card-title">Leave Request Calendar</h3>
            </div>
            <!-- /.card-header -->
            <!-- form start -->

  <div class="card-body">
   {{ Form::model(request(),['method'=>'get']) }}
  <div class="row" style="margin-bottom: 10px">
    <div class="col-sm-4">
        {{ 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>

<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.1.0/fullcalendar.min.css'>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.1.0/fullcalendar.print.css" media='print'>
    <!--</div>-->

   <div class="card-body p-0"> 
        <div id='calendar'></div>
    </div>


<!--</div>-->  

  </div>

    <!-- /.card -->
   </div>
   <!--/.col (left) -->
  </div>
<!-- /.row -->
</div>

<script>
 $(document).ready(function () {
        // page is now ready, initialize the calendar...
        let year = new Date().getFullYear();
        $('#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>

当我渲染页面时,日历上没有任何显示。

leave calendar

但是当我在桌子上渲染相同的东西时,它显示:

                @foreach($leaverequests as $key => $leaverequest)
                        <td>
                            {{$key+1}}
                        </td>
                        <td>
                            {{isset($leaverequest->leavetype) ? $leaverequest->leavetype->leave_type_name : 'N/A'}}
                        </td>
                        <td>
                            {{isset($leaverequest->reason) ? $leaverequest->reason : 'N/A'}}
                        </td>
                        <td>
                            {{Carbon\Carbon::parse($leaverequest->commencement_date)->format('d-m-Y') ?? '' }}                             
                        </td>
                        <td>
                            {{Carbon\Carbon::parse($leaverequest->resumption_date)->format('d-m-Y') ?? '' }} 
                        </td>
                        <td>
                            {{isset($leaverequest->no_of_days) ? $leaverequest->no_of_days : 'N/A'}}
                        </td>   
                        <td>
                            {{Carbon\Carbon::parse($leaverequest->created_at)->format('d-m-Y') ?? '' }} 
                        </td>                                          
                </tr>
                @endforeach 

leave table

为什么我的日历有这个问题?

我该如何解决?

谢谢

0 个答案:

没有答案