-1

This is my code:

 $evaluationjob = evaluation_elements_jobs::where('job_id', $user->job_id)
          ->where('company_id',$company_check->id)
          ->first();

The error in this line:

         $items = json_decode($evaluationjob["element_degree"]);

The error message is:

Trying to access array offset on value of type null

Teemu
  • 22,918
  • 7
  • 53
  • 106

2 Answers2

0

You can try this:

$evaluationjob = evaluation_elements_jobs::where('job_id', $user->job_id)
      ->where('company_id',$company_check->id)
      ->first();

if ($evaluationjob != null && isset($evaluationjob["element_degree"])) {
    $items = json_decode($evaluationjob["element_degree"]);
}

This will check if $evaluationjob is not null and if the value $evaluationjob["element_degree"] exists in the variable.

MESP
  • 486
  • 2
  • 17
0

The error you are having here is the fact that you're trying to access a property on a variable that is null;

So you need to put a check on the variable and the property.

if ($evaluationjob != null && isset($evaluationjob["element_degree"])) {
    $items = json_decode($evaluationjob["element_degree"]);
}
Solar
  • 870
  • 9
  • 18