lundi 31 décembre 2018

Invalid argument supplied for foreach() (View:

I'm tryingo to render data on a table in laravel view as always did, but in this case i'm obtaining an classic php error

Invalid argument supplied for foreach()

I assumed that it's an error related with the type of the variable that i'm using in the foreach, but i'm using a collection as always did.

This is my code:

Controller

 public function getAfiliaciones()
    {


        $roleId = Auth::user()->roleId;
        $provinciaId = Auth::user()->provinciaId;


        if ($roleId == "3") {

            $regAfiliate = Afiliacion::where('provinciaId', $provinciaId)->limit(5)->get();


            foreach($regAfiliate as $afiliate){


            $afiliate->provinciaId = array_get(Provincia::where('id',$afiliate->provinciaId)->pluck('nombre'),0);

            }

            return view('afiliaciones',['regAfiliate' => $regAfiliate]);


         }elseif ($roleId == "1"){

            $regAfiliate = Afiliacion::all();

            foreach($regAfiliate as $afiliate){


                $afiliate->provinciaId = array_get(Provincia::where('id',$afiliate->provinciaId)->pluck('nombre'),0);

            }



            return view('afiliaciones',['regAfiliate' => $regAfiliate]);


        }else{

            return view('afiliaciones');
        }


    }

View

  <table id="afiliaciones" class="table table-striped table-bordered table-hover" >
                    <thead>
                        <tr>
                            <th nowrap>ID</th>
                            <th nowrap>Fecha de Registro</th>
                            <th nowrap>Nombre</th>
                            <th nowrap>Apellido</th>
                            <th nowrap>DNi</th>
                            <th nowrap>Sexo</th>
                            <th nowrap>Email</th>
                            <th nowrap>Nombre de la Madre</th>
                            <th nowrap>Nombre del Padre</th>
                            <th nowrap>Fecha de Nac</th>
                            <th nowrap>Domicilio</th>
                            <th nowrap>Provincia</th>
                            <th nowrap>Cod. Postal</th>
                            <th nowrap>Telefono</th>
                            <th nowrap>Ceular</th>
                        </tr>
                    </thead>
                    <tbody>

                            @if(isset($regAfiliate))

                                @foreach ($regAfiliate as $registro)
                            <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                            </tr>


                            @endforeach
                       @endif


                    </tbody>

                </table>

If someone can help me i'll be very thankful!!



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2ApMfE1
via IFTTT

Aucun commentaire:

Enregistrer un commentaire