Blade directives aren't working, code keeps showing in the browser instead of executing

615 views Asked by At

My blade directives aren't working, as you see I don't have the PHP code in PHP tags, because its a blade directive and I'm not supposed to add those. But for some reason the PHP code keeps showing in the browser and not executing, why is this happening?

Also, in my text editor, the PHP code color is white, which I can tell is a problem. I think that the code is outdated, and if so, how can I get it up to date?

I'm using Laravel 5.5, and my PHP version is 7.0.

@foreach($posts as $post)
    <div class="post" data-postid="{{ $post->id }}">
        <a href="#"><h3>{{ $post->title }}</h3></a>
        <h6>Posted on {{ $post->created_at }} by {{ $post->user->name }}</h6>
        <p>{{ $post->body }}</p>
        <div class="interaction">
            <a href="#">Likes</a>
            <a href="#">Dislikes</a>
            <hr>
        </div>
    </div>
@endforeach
2

There are 2 answers

0
Source Edin On

Your file must have .blade extension in it, otherwise @, {{ }} etc would not be recognize, and would not work. Check if your files are named correctly like example.blade.php

0
Walter Garcia On

Blade view files use the .blade.php file extension...So your file MUST be something.blade.php otherwise, blade syntax will not be recognized...Double check your file name.

About the code color ... Which editor do you use?

Sublime text 3 - PHP code and BLADE syntax are white.

VScode - PHP code and BLADE syntax are white.

Atom - PHP code and BLADE syntax are light gray.