Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

futonox's avatar

Weird behavior of Blade using variables from Eloquent - depending on PHP-code doing the same in between

Blade is showing object from Eloquent different depending on PHP code in between.

Three tables with the same information showing. The second table is doing it with PHP. The first and third table is doing it with blade.

Having the following in a view:

<h2>Table One</h2>
<table>
@foreach ($accountchart as $ac)
    <tr>
        <td>
            <p>{{ $ac->text }}</p>
        </td>
        <td>
            <p>- {{ isset($ac->accountcharttype) ? $ac->accountcharttype->title : ''  }}</p>
        </td>
    </tr>
@endforeach
</table>

<h2>Table two</h2>
<table>

php-> foreach ($ accountchart as $ ac2) { <-php

php-> echo $ ac2->text; <-php

- php-> if ( $ ac2->accountcharttype ) { echo $ ac2->accountcharttype->title; } <-php

php-> } <-php


<h2>Table three</h2>
<table>
@foreach ($accountchart as $ac)
    <tr>
        <td>
            <p>{{ $ac->text }}</p>
        </td>
        <td>
            <p>- {{ isset($ac->accountcharttype) ? $ac->accountcharttype->title : ''  }}</p>
        </td>
    </tr>
@endforeach
</table>

THE PROBLEM: The right column in the first table is empty - but the right column is filled with elements in the third table - even thou the code for producing table one and table three is equal (via Blade).

Picture of the output in the tables: http://postimg.org/image/elsud6q8p/

Somehow does the use of PHP in between make the Blade-code work.... ??...

... weird.

A bug?...

Any comments?...

(Laravel 5.1, Ubuntu 14.04 server, operating system updated, Apache, MySQL)

0 likes
2 replies
StuffedGoat's avatar

Have you found a solution yet? This looks very strange to me too.

Maybe you could try and tidy up a bit via and see if that helps:

php artisan view:clear
php artisan cache:clear
helmerdavila's avatar

Compare the blade files to compiled php views in, there are some extra functions

your_project\storage\framework\views

Please or to participate in this conversation.