Link to home
Create AccountLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

asked on

Could you point how to handle Undefined Offset Error in Laravel?

Hi Experts

Could you point  how to handle Undefined Offset Error in Laravel?

This code:

        $registros = array();

        for($indexDistribuidor = 0; $indexDistribuidor<count($metas); $indexDistribuidor += 12){
            $item = array();
            array_push($item, $metas[$indexDistribuidor]->razaosocial);
            array_push($item, $metas[$indexDistribuidor]->cnpj);
            for($indexMes = 0; $indexMes < 12; $indexMes++){
                array_push($item, $metas[$indexDistribuidor + $indexMes]->meta);
            }

            array_push($item, $metas[$indexDistribuidor]->distribuidor_id);
            array_push($item, $ano);

            array_push($registros, $item);
        }

        return $registros;
		

Open in new window


During the foreach the array of objects is correctly been mounted.

But at certain point this offset error is produced:

 User generated image
Any workaround?

Thanks in advance.
Avatar of Bhavesh Shah
Bhavesh Shah
Flag of India image

hi,


you can fix this using isset().


did you try it?

ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Eduardo Fuerte

ASKER

Hi Chris

By using your code the error doesn't occurs at controller but  now  is occurring at view...



It's due 12 months possible to present data at view.

The previous query that must to generate data have to be adjusted to get only 12 lines per "distribution company".
Really

After correcting the query everything is OK.

But your suggestion is pretty good.

Thank you!