How to pass two parameters in datatable's with request in jquery and laravel

Advertisements

I need to run a function to check for validity, I need to pass two variables with request. If possible I need to use in Datatable.

Example

return datatables()
            ->of($employee)
            ->addIndexColumn()
            ->addColumn('action', function($row) use ($attendanceDate) 
            {
                $btnId = $row->company_id."_".$row->branch_id."_".$row->id."_".$attendanceDate."_".$row->department_id."_".$row->designation_id;
                $btn='';
                $status = Attendance::where([['employee_id', '=', $row->id],['current_date', '=', $attendanceDate]])->first();
                if ((Auth::user()->hasPermissionTo('attendance-create') || Auth::user()->hasPermissionTo('attendance-update')) &&  !isset($request->day_wise) )
                {
if($current_day>=3 && $given_month==$current_munth && $left_days<8)
                        {
                           
 if(isset($status->status) && $status->status!=2 && $status->working_time <'08:00:00'){
                                $btn .= '<a href="javascript:void(0)" class="btn btn-info btn-outline btn-    circle btn-lg attendance_employee" employee_name="'.$row->name.'" table_id="'.$btnId.'" data-toggle="tooltip" title="Attendance"><i class="fas fa-clock"></i></a>';

                            }
                        }
      
                    }
                    
                }
 return $btn;

Now I need both $row and $attendanceDate to check inside addColumn with not isset $request value in query. If i use the function as above it throws an error [the above code doesnot work with request parameter]. If I try to use a $attendanceDate from outside then datatable .

I need solution which could either work as below:

  1. return $btn or button show in view with condition base
  2. If possible addColoumn ‘action’ hide if $request->day_wise not set

>Solution :

Please pass the request variable in use keyword like below code.

return datatables()
            ->of($employee)
            ->addIndexColumn()
            ->addColumn('action', function($row) use ($attendanceDate,$request) 
            {
                $btnId = $row->company_id."_".$row->branch_id."_".$row->id."_".$attendanceDate."_".$row->department_id."_".$row->designation_id;
                $btn='';
                $status = Attendance::where([['employee_id', '=', $row->id],['current_date', '=', $attendanceDate]])->first();
                if ((Auth::user()->hasPermissionTo('attendance-create') || Auth::user()->hasPermissionTo('attendance-update')) &&  !isset($request->day_wise) )
                {
if($current_day>=3 && $given_month==$current_munth && $left_days<8)
                        {
                           
 if(isset($status->status) && $status->status!=2 && $status->working_time <'08:00:00'){
                                $btn .= '<a href="javascript:void(0)" class="btn btn-info btn-outline btn-    circle btn-lg attendance_employee" employee_name="'.$row->name.'" table_id="'.$btnId.'" data-toggle="tooltip" title="Attendance"><i class="fas fa-clock"></i></a>';

                            }
                        }
      
                    }
                    
                }
 return $btn;

Leave a ReplyCancel reply