为foreach()提供了无效的参数(查看:

时间:2018-12-31 22:55:56

标签: laravel-5 view laravel-collection

我正试图像往常一样在laravel视图中呈现表上的数据,但在这种情况下,我会遇到经典的php错误

  

为foreach()提供的参数无效

我认为这是与我在foreach中使用的变量类型有关的错误,但是我像往常一样使用集合。

这是我的代码:

  

控制器

 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');
        }


    }
  

查看

  <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>{{$registro->id}}</td>
                                    <td>{{$registro->created_at}}</td>
                                    <td>{{$registro->nombre}}</td>
                                    <td>{{$registro->apellido}}</td>
                                    <td>{{$registro->dni}}</td>
                                    <td>{{$registro->sexo}}</td>
                                    <td>{{$registro->email}}</td>
                                    <td>{{$registro->nombreMadre}}</td>
                                    <td>{{$registro->nombrePadre}}</td>
                                    <td>{{$registro->fechaNac}}</td>
                                    <td>{{$registro->domicilio}}</td>
                                    <td>{{$registro->provinciaId}}</td>
                                    <td>{{$registro->codPostal}}</td>
                                    <td>{{$registro->telefono}}</td>
                                    <td>{{$registro->movil}}</td>
                            </tr>


                            @endforeach
                       @endif


                    </tbody>

                </table>

如果有人可以帮助我,我将非常感激!

0 个答案:

没有答案