Avatar of Eduardo Fuerte
Eduardo Fuerte
Flag 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:

Any workaround?

Thanks in advance.

Avatar of undefined
Last Comment
Eduardo Fuerte

8/22/2022 - Mon
Bhavesh Shah


you can fix this using isset().

did you try it?

Chris Stanyon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Eduardo Fuerte

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".
Eduardo Fuerte


After correcting the query everything is OK.

But your suggestion is pretty good.

Thank you!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck