I can not list an array in a blade view "Trying to get property of non-object"

0

I need to list some boxes in a quote. inside the gallery view add checkbox inside an array to send them to the controller and this sends them to the view that I need to contact. this data comes to the view but it throws me the following error

  

"Trying to get property of non-object"

Controller

 public function ListarCuadrosCotizacion(Request $request){

    //recibimos el request enviado desde la galeria

    $cuadros = $request->all();
   //return $cuadros;
     return view('contacto',compact('cuadros'));


}

Route

Route::get('/cotizaciones', [ 
 'as'=>'galeria_cotizacion',
 'uses'=>'[email protected]'] );

Vista home     

@foreach ($cuadros as $cuadro)      
<div class="col-md-4 col-xs-6 work">

@if(Storage::disk('images')->has($cuadro->image))        
<input class="radio" type="checkbox" name="cuadro[]" value="{{$cuadro}}" >  
                    <img src="{{ url('/miniatura/'.$cuadro->image)}}" />
    <div class="work-content">
            {{ csrf_field() }}  
    </div>

@endif
</div>


@endforeach


<button type="submit" class="btn btn-primary">Enviar</button>
</form>

Contact view

<table class="table table-striped">
<thead>
        <tr>
            <th>id</th>

            </tr> 
</thead>
    <tbody>                             
        <tr>
        @foreach($cuadros as $row)

            <td>
                 {{$row->id}}</td>  
            </tr>
        @endforeach 
        </tbody>
</table>

I leave some of my tests,

    
asked by bguardian 17.12.2018 в 22:05
source

1 answer

0

Fix the problem, this was in the controller and in the home view

  Controlador

  public function ListarCuadrosCotizacion(Request $request){
    //recibimos el request a traves de un array de checkbox y enviamos el listado a contacto                
    $cuadros = $request['cuadrolistado'];
    $cuadros_view = array();
    //dd($cuadros);
    foreach ( $cuadros as $cuadro_id ) {       
        // llamada a la bd por id
        $_cuadrito = Cuadro::find($cuadro_id);
         // agregar cuadro BD a  cuadros_bd       
        $cuadros_view[] = $_cuadrito;

    }      
    return view('contacto',array(
        'cuadros' =>  $cuadros_view         
    ));


}

And in my view, home was sending the object and not the id.          

                @foreach ($cuadros as $cuadro)      
                <div class="col-md-4 col-xs-6 work">

                    @if(Storage::disk('images')->has($cuadro->image))        
                    <input class="radio" type="checkbox" name="cuadrolistado[]" value="{{$cuadro->id}}" >  
                    <img src="{{ url('/miniatura/'.$cuadro->image)}}" />
                <div class="work-content">
                        {{ csrf_field() }}  
                </div>

                @endif
               </div>


               @endforeach


                    <button type="submit" class="btn btn-primary">Enviar</button>
            </form>
    
answered by 19.12.2018 в 03:38