Reputation: 97
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:
Upvotes: 2
Views: 383
Reputation: 104
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;
Upvotes: 2