2
I’ve got a little problem I haven’t figured out yet, I’ve got a View
and I can’t get into foreach
of the same, follows the 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 the foreach
everything goes normal, even in the test done but does not enter the foreach
for nothing in this world, what did I do wrong?
PS: I searched in a lot of places including here on the site and could not find anything in that sense, I saw many problems of foreach
but none similar to this, if there is already something with the same idea that can help could please direct me?
Dump result before the foreach
:
Tiprinter {#898 #fillable: array:9 [ 0 => "asset" 1 => "ip" 2 => "tag" 3 => "model" 4 => "tonner" 5 => "sector" 6 => "date purchase" 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 "patrimonio" => 35 "ip" => "" "tag" => "Brohter" "model" => "DCP-J125" "tonner" => "Ink" "sector" => "T.I." "datacompra" => "2015-08-05" "local" => "MG0" "active" => "S" "created_at" => null "updated_at" => "2018-04-13 19:14:06" ]] #original: array:12 [ "id" => 1 "patrimonio" => 35 "ip" => "" "tag" => "Brohter" "model" => "DCP-J125" "tonner" => "Ink" "sector" => "T.I." "datacompra" => "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 don’t know if this is how I should format...
$printer is not a list! So it doesn’t work
– novic
Hi @Virgilio Novic, thanks for answering, but I still got in doubt, by list you mean array right? If this is the case, in the test I did, out of the foreach it returns me the array as it should but, inside the foreach not, by the way, nor enter?
– Gabriel Sassaki
$impressora = $this->TiImpressoraM->find($id);
return a printer ornull
, ai I was in doubt you want to return only one or a list of printers?– novic
Return me the array with the information of a specific printer, as I expected.
– Gabriel Sassaki
So this command returns a printer so this is what you want to test if the printer returned values in object or array???
– novic
What I need is the same array, inside the foreach, I need some volores inside the array to pass them to the view and eventually also use these values for another operation.
– Gabriel Sassaki
$impressora = $this->TiImpressoraM->all()
this return you the collection (orarray
) the other way a printer! which of the two ...?– novic
Sorry @Virgilio Novic, I don’t understand the question...
– Gabriel Sassaki
Let’s try to understand: the command you gave in
controller
returns an instance of that Tiprinted class, then you went toView
is want to print the collection of this class, this will not work because $printer is a printer and is not a printer collection. If the command is right oncontroller
theforeach
is wrong inView
? I already asked you if it is a printer the result even if it is I tell you what to do!– novic
Sorry @Virgilio Novic, you may have noticed that I am very new in PHP and Laravel, anyway, I posted the result of the Dump before the foreach in the original question, if it helps...
– Gabriel Sassaki
No problems you want a result just look at the answer
– novic
A question, why are you trying to iterate a Model and are still using the name
$sheets
? Wouldn’t you want to pick up a relationship from that Model? Type$impressora->sheets
?– fernandosavio