2

im working with lravel 7 project before i used to work with xampp 7.3.21 / PHP 7.3.21 and everything is so good ive upgraded to xampp 7.4.9 / PHP 7.4.9 and i get

Trying to access array offset on value of type null 

in the most of my porject and this is example

public function show
(
    $id,
    // selects
        $selects_names,
        $selects_languages,
        $selects_models,
        $selects_policies,
        $selects_types,
        $selects_ranks,
    // end selects
)
{
    return view('curd.show',compact
    (
        'id'
        // select
            'selects_names',
            'selects_languages',
            'selects_models',
            'selects_policies',
            'selects_types',
            'selects_ranks',
        // end selects
    ));
}

and this is the blade code

    @if($selects_names)
    @foreach($selects_names as $key => $selects_name)
        @include(
            'treats.show_selects',
            [
                'name' => $selects_name,
                'language' => $selects_languages[$key],
                'model' => $selects_models[$key],
                'policy' => $selects_policies[$key]  ?? null,
                'show_type' => $selects_types[$key],
                'rank' => $selects_ranks[$key] ?? null,
            ]
        )
    @endforeach
@endif

and always get the above error most of my program is included from the code above they are treate function and now most of it now working

softya
  • 229
  • 7
  • 22
  • 1
    you can debug the array selects_names and see what is the format for accessing the array and do it like that. – Naveed Ali Aug 29 '20 at 20:18
  • 1
    Use `@if(count($selects_names))` in view – Sobir Aug 29 '20 at 20:35
  • 1
    Are you sure all the keys in `$select_names` exist in all the other arrays? Try to define a default value for the other arrays as you did for `$select_policies` and `$select_ranks`. And check this [question](https://stackoverflow.com/q/59336951/14066311) – Prince Dorcis Aug 29 '20 at 20:37

1 Answers1

2

Some key in $select_names is probably not in the other arrays. Define a default value for the other arrays as you did for $select_policies and $select_ranks:

[
    'name' => $selects_name,
    'language' => $selects_languages[$key] ?? '',
    'model' => $selects_models[$key] ?? null,
    'policy' => $selects_policies[$key]  ?? null,
    'show_type' => $selects_types[$key] ?? null,
    'rank' => $selects_ranks[$key] ?? null,
]
Prince Dorcis
  • 955
  • 7
  • 7