Monica
Monica

Reputation: 1534

Laravel is giving me Undefined variable Error Exception

I have this code:

        <? $counter = 1 ?>

        <div id="container_blog_all">
            @foreach ($posts as $post)
                <div class="blog_block" style="@if($counter % 3 == 0) margin-right:0px @endif">
                    <a href="{{ $post->url() }}"><img class="blog_block_cover" src="{{ URL::to('uploads/blog/cover/'.$post->cover) }}"></a>
                    <div class="blog_block_date">{{ $post->date }}</div>
                    <div class="blog_block_sep"></div>
                    <div class="blog_block_title">{{ $post->title }}</div>
                </div>
                <? $counter++; ?>
            @endforeach
        </div>

And I am getting this error, any reasons why??

enter image description here

I can see the the variable counter is defined, so why am I getting this error?

Upvotes: 0

Views: 1468

Answers (2)

Abhay PS
Abhay PS

Reputation: 4175

Looks like laravel doesn't like php short tags, it is better you use <?php $counter = 1 ?> rather than <? $counter = 1 ?>.That should resolve the error also.

Upvotes: 0

snollygolly
snollygolly

Reputation: 1886

You're missing a semicolon:

<? $counter = 1 ?>

should be

<? $counter = 1; ?>

Upvotes: 2

Related Questions