jeudi 21 mai 2020

because it shows Undefined offset: 0, seeder laravel?

I have the following for in which I create the records

foreach ($v as $k => $f){
            if($v[$k] !=  false && $f['zip_code'] !=''){
                $state = State::whereCode($f['code'])->get();
                var_dump($state[0]->id);
                  \App\Models\ZipCodes::create([
                    'uuid'  => Uuid::generate(4)->string,
                    'zip_code'  => $f['zip_code'],
                    'city'  => $f['city'],
                    'county'  => $f['county'],
                    'state_id'  => $state[0]->id,
                ]); 
            }
        }

I have noticed that the error appears in the field 'state_id' => $ state [0] -> id since if I comment and delete it from the table it doesn't give me the error.

In fact if I just leave

foreach ($v as $k => $f){
            if($v[$k] !=  false && $f['zip_code'] !=''){
                $state = State::whereCode($f['code'])->get();
                var_dump($state[0]->id);
            }
}

The same generates the error.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2LRqeD8
via IFTTT

Aucun commentaire:

Enregistrer un commentaire