Which line?
Oct 8, 2022
3
Level 2
TypeError Cannot access offset of type string on string http://127.0.0.1:8000/employees/monthly/salary/payslip/10/1970-01-09
I get this error: TypeError Cannot access offset of type string on string http://127.0.0.1:8000/employees/monthly/salary/payslip/10/1970-01-09
In controller
public function MonthlySalaryPayslip(Request $request,$id,$date)
{
$date['y'] = date('Y', strtotime($date));
dd($date['y']);
$date['m'] = date('m', strtotime($date));
$data['details'] = EmployeeAttendance::whereYear('date', $date['y'])->whereMonth('date', $date['m'])->where('employee_id', $id)->get();
}
I get date and id from URL.
Level 4
Is $date a string? If so you won’t be able to access it like you are. You’ll need to parse the string to a date using Carbon for instance or DateTime and then get the parts from that. Alternatively if your string is always in the format Y-m-d then you could explode the string at the - and then use the parts from that so $date[0] would be your year, 1 month and 2 day. See here the php manual:
1 like
Please or to participate in this conversation.