Laravel Blade prints unknown values

Asked

Viewed 418 times

1

I use Laravel 5.3.

I have a variable that returns this value in a var_dump():

 array(3) {
  [1]=>
  string(5) "10:00"
  [2]=>
  string(5) "10:20"
  [3]=>
  string(5) "11:40"
}

But if I give:

@foreach($variavel as $valor)
    <label for="{{$valor}}"> {{$valor}} </label>
    <input type="checkbox" id="{{$valor}}" name="horario[0][]" />
@endforeach

He printed it out:

<label for="10:00">10:00</label>
<input type="checkbox" id="10:00" name="horario[0][]" />
<label for="10:20">10:20</label>
<input type="checkbox" id="10:20" name="horario[0][]" />
<label for="11:40">11:40</label>
<input type="checkbox" id="11:40" name="horario[0][]" />

And if I do:

@foreach($variavel as $valor)
    <label for="{{print $valor}}"> {{print $valor}} </label>
    <input type="checkbox" id="{{print $valor}}" name="horario[0][]" />
@endforeach

I printed it out:

10:00 1 10:20 1 11:40 1

I do not understand where this number 1 can come from after each printed value, because if I do this print within the tags of PHP he does not appear. What could cause this? Could I be clear? ps.: between value and number 1 appears checbox?

  • 1

    Enter all foreach code

  • Thanks for the help @foreach($horarios_free as $horario_free) {print $horario_free}} @endforeach If I use {{$horario_free}} it prints the HTML code, this: <input value="10:00" type="checkbox" name="time[0]]"/>, instead: 10:00

1 answer

3


You’re using it wrong, in the code {{ }} is replaced for:

<?php echo e($horario_livre); ?> 

then the correct code would be:

@foreach($horarios_livres as $horario_livre) 
    {{$horario_livre}}     
@endforeach

without the need to print. When is the print just to get an idea, the code is generated:

<?php echo e(print $horario_livre); ?> 

and the output at the end is a number 1 because of print returns an integer, online example.

References:

  • So Virgilio, I know that {{}} subistitui the echo, as I commented in his first answer here. But it happens to display this "<p>paragrafo</p>" and not this "paragrafo"; already with print works, but appears this number 01 of darkness. Thank you for your attention

  • Do you want to print an html tag? @Clebermartins, Edit your question correctly, just remember, you’re doing it wrong!

  • I edited the question and tried to be as clear as possible. If you still have doubt I can try to clear mias. Thanks

  • @Clebermartins I explained the reason and the error, it prints one as satisfactory result of the print, but there do not need to use print as explained in the answer, so much so that you yourself asked the question right and wrong. 1 is the return of the print because echo print "text"; prints text1.

  • Right. I’ll use the PHP tags myself because it works as it should. I do not consider wrong form but a resource to use print, since the standard resource {{}} does not return a satisfactory value (it is displaying HTML as text). Thank you anyway for trying.

  • @Clebermartins has two forms utilize {!!$variável!!} for html. You need to read the documentation to understand how p framework works. The attempt and the way of.perguntar this bringing confusion of.entendimentonto. I hope that this resolves

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.