I can not get into the foreach of a blade in laravel 5.7

2

I have a small problem that I still can not figure out how to solve, I have a View and I can not get into foreach of this same, follow View :

<div class="form-group">
    {!! csrf_field() !!}        

    <!--{{ dd($impressora) }}-->
    @foreach($impressora as $sheets)
        {{ dd('teste') }}
        <!--{{ dd($sheets) }}-->
        <div class="form-row">
            <div class="form-group col-md-4">
                <label for="setor">Setor*:</label>
                <input class="form-control" placeholder="Digite o setor..." required="required" name="setor" type="text" value="{{ $sheets->setor }}" id="setor">
            </div>
            <div class="form-group col-md-4">
                <label for="marca">Marca*:</label>
                <input class="form-control" placeholder="Digite a marca..." required="required" name="marca" type="text" value="{{ $sheets->marca }}" id="marca">
            </div>
            <div class="form-group col-md-4">
                <label for="modelo">Modelo*:</label>
                <input class="form-control" placeholder="Digite o modelo..." required="required" name="modelo" type="text" value="{{ $sheets->modelo }}" id="modelo">
            </div>     
        </div>

        <div class="form-row">
            <div class="form-group col-md-4">
                <label for="tipo">Tipo*:</label>
                <input class="form-control" placeholder="Digite o tipo do tonner..." required="required" name="tipo" type="text" value="Tinta" id="tipo">
            </div>
            <div class="form-group col-md-4">
                <label for="tonner">Tonner*:</label>
                <input class="form-control" placeholder="Digite o modelo do tonner..." required="required" name="tonner" type="text" value="Tinta" id="tonner">
            </div>
            <div class="form-group col-md-4">
                <label for="setor">Setor*:</label>
                <input class="form-control" placeholder="Digite o setor..." required="required" name="setor" type="text" value="T.I." id="setor">
            </div>
        </div>

        <div class="form-row">
            <div class="form-group col-md-4">
                <label for="local">Local*:</label>
                <select class="form-control" required="required" id="local" name="local">
                    <option value="MG0" selected="selected">Fábrica Minas</option>
                    <option value="SP0">Loja SP Mendes Júnior</option>
                    <option value="SP1">Loja SP Xavantes</option>
                </select>
            </div>
            <div class="form-group col-md-4">
                <label for="datacompra">Data da Compra*:</label>
                <input class="form-control" required="required" name="datacompra" type="date" value="2015-08-05" id="datacompra">
            </div>
            <div class="form-group col-md-4">
                <label for="ativo">Em Uso*:</label>
                <select class="form-control" required="required" id="ativo" name="ativo">
                    <option value="S" selected="selected">Sim</option>
                    <option      value="N">Não</option>
                    <option value="0">Descartado</option>
                </select>
            </div>
        </div>
    @endforeach
</div>

This is the controller:

public function tonerSheets($id)
{        
    $impressora  = $this->TiImpressoraM->find($id);                
    return view('portal.ti.impressoras.TiImpressorasToner', compact('impressora'));
}

Before foreach everything is normal, including the test done but does not enter foreach for nothing in the world, what did I do wrong?

PS: I searched a lot of places including here on the site and could not find anything like it, I saw many problems with foreach but none like this , if there is already something with the same idea that could help please could you please direct me?

Dump result before foreach :

  

TiIpressor {# 898 ▼     #fillable: array: 9 [▼       0 = > "patrimony"       1 = > "ip"       2 = > "brand"       3 = > "model"       4 = > tonner       5 = > "sector"       6 = > "databought"       7 = > "local"       8 = > "active"     ]     #connection: "mysql"     #table: null     #primaryKey: "id"     #keyType: "int"     + incrementing: true     #with: []     #withCount: []     #perPage: 15     + exists: true     + wasRecentlyCreated: false     #attributes: array: 12 [▼       "id" = > 1       "heritage" = > 35       "ip" = > ""       "mark" = > "Brohter"       "template" = > "DCP-J125"       "tonner" = > "Ink"       "sector" = > "YOU."       "databought" = > "2015-08-05"       "local" = > "MG0"       "active" = > "S"       "created_at" = > null       "updated_at" = > "2018-04-13 19:14:06"     ]     #original: array: 12 [▼       "id" = > 1       "heritage" = > 35       "ip" = > ""       "mark" = > "Brohter"       "template" = > "DCP-J125"       "tonner" = > "Ink"       "sector" = > "YOU."       "databought" = > "2015-08-05"       "local" = > "MG0"       "active" = > "S"       "created_at" = > null       "updated_at" = > "2018-04-13 19:14:06"     ]     #casts: []     #dates: []     #dateFormat: null     #appends: []     #events: []     #observables: []     #relations: []     #touches: []     + timestamps: true     #hidden: []     #visible: []     #guarded: array: 1 [▼       0 = > "*"     ]   }

I do not know if this is how I should format it ...

    
asked by anonymous 19.12.2018 / 18:29

1 answer

1

You are not returning a collection, you are returning a single data, remove foreach and enter a if , eg:

<div class="form-group">
    {!! csrf_field() !!}        
    @if(isset($impressora))            
        <div class="form-row">
            <div class="form-group col-md-4">
                <label for="setor">Setor*:</label>
                <input class="form-control" placeholder="Digite o setor..." required="required" name="setor" type="text" value="{{ $sheets->setor }}" id="setor">
            </div>
            <div class="form-group col-md-4">
                <label for="marca">Marca*:</label>
                <input class="form-control" placeholder="Digite a marca..." required="required" name="marca" type="text" value="{{ $sheets->marca }}" id="marca">
            </div>
            <div class="form-group col-md-4">
                <label for="modelo">Modelo*:</label>
                <input class="form-control" placeholder="Digite o modelo..." required="required" name="modelo" type="text" value="{{ $sheets->modelo }}" id="modelo">
            </div>     
        </div>

        <div class="form-row">
            <div class="form-group col-md-4">
                <label for="tipo">Tipo*:</label>
                <input class="form-control" placeholder="Digite o tipo do tonner..." required="required" name="tipo" type="text" value="Tinta" id="tipo">
            </div>
            <div class="form-group col-md-4">
                <label for="tonner">Tonner*:</label>
                <input class="form-control" placeholder="Digite o modelo do tonner..." required="required" name="tonner" type="text" value="Tinta" id="tonner">
            </div>
            <div class="form-group col-md-4">
                <label for="setor">Setor*:</label>
                <input class="form-control" placeholder="Digite o setor..." required="required" name="setor" type="text" value="T.I." id="setor">
            </div>
        </div>

        <div class="form-row">
            <div class="form-group col-md-4">
                <label for="local">Local*:</label>
                <select class="form-control" required="required" id="local" name="local">
                    <option value="MG0" selected="selected">Fábrica Minas</option>
                    <option value="SP0">Loja SP Mendes Júnior</option>
                    <option value="SP1">Loja SP Xavantes</option>
                </select>
            </div>
            <div class="form-group col-md-4">
                <label for="datacompra">Data da Compra*:</label>
                <input class="form-control" required="required" name="datacompra" type="date" value="2015-08-05" id="datacompra">
            </div>
            <div class="form-group col-md-4">
                <label for="ativo">Em Uso*:</label>
                <select class="form-control" required="required" id="ativo" name="ativo">
                    <option value="S" selected="selected">Sim</option>
                    <option   value="N">Não</option>
                    <option value="0">Descartado</option>
                </select>
            </div>
        </div>
    @end
</div>
    
19.12.2018 / 20:03