-1

I recently found strange behavior of blade in Laravel 5.8.

Let's say I have in file

@extends('layout')
@section('title','Dodaj playlistę')

@section('content')

 {{$hosts = \App\Host::all()}}

<h2>Dodaj audycję do bazy</h2>

in the middle of the file I have

 {{$hosts = \App\Host::all()}}

    @foreach ($hosts as $man)
       <option value='{{$man->id}}'>{{$man->name}} </option>
    @endforeach

enter image description here The problem is I always get the first $hosts variable echoed, while second not. What the hell? Such variable shouldn't be echoed at all because the command is only variable value attribution.

I've checked all my routes, there is no dd() or var_dump() command anyhere.

Sebastian
  • 448
  • 4
  • 14

2 Answers2

0

Looks like possibly a typo pushing for two sections within one. It should normally throw an error, but might be getting confused with the different language.

Change @section('title','Dodaj playlistę') to @section('title') and give it a try.

Also, set the var directly in the foreach for better clarity:

@foreach ($hosts as $man)

Becomes

@foreach(\App\Host::all() as $man)
Watercayman
  • 7,970
  • 10
  • 31
  • 49
0

{{$hosts = \App\Host::all()}} that will echo "\App\Host::all()"

you can

@php
   $hosts = \App\Host::all()
@endphp

but it is discouraged to do in a view see here How to Set Variables in a Laravel Blade Template

porloscerros Ψ
  • 4,808
  • 2
  • 11
  • 20