How to fix 'unexpected token "endif"' in your Blade files when using Prettier

Posted on December 19, 2025

Laravel PHP Blade

If you are using Blade with Prettier, 99% of the time it does a great job of formatting your files. Occasionally though, you may run into some issues that seem inconspicuous, but they are enough to prevent you from working on the things that matter.

For example, let's take this simple route directive:

<a href="{{ route('posts.show', $post->id) }}">View This Long Post</a>

By default, this works absolutely fine. Upon formatting though, it no longer works and throws an exception syntax error, unexpected token "endif".

Can you spot why in the example below...? 👀

<a href="{{ route("posts.show", $post->id) }}">View</a>

...The eagle eyed will notice that double quotations are wrapping the route name, inside double quotations on the href property, which is incorrect syntax.

Let's fix "syntax error, unexpected token "endif""

If you haven't already, you will need to create a .prettierrc file at the root of your project. If you are using the prettier-plugin-blade package it's likely you already have one.

Within the .prettierrc json object you will need to ensure single quotes are set to true i.e. "singleQuote": true. After adding this and re-saving your Blade file, you no longer get the exception because single quotes are persisted.

I use this prettier config, which you are free to copy:

{
    "trailingComma": "all",
    "tabWidth": 4,
    "semi": false,
    "endOfLine": "lf",
    "printWidth": 120,
    "singleQuote": true,
    "plugins": ["prettier-plugin-blade"],
    "proseWrap": "preserve",
    "pluginSearchDirs": false,
    "overrides": [
        {
            "files": ["*.blade.php"],
            "options": {
                "parser": "blade",
                "proseWrap": "never"
            }
        }
    ]
}

Additionally, you may also want to set up a .prettierignore file to format your .blade.php files but not your .php files, to prevent conflict of interests.

Add the file to the root of your project with the following:

# Ignore normal PHP files
*.php

# But don't ignore Blade templates
!*.blade.php

Now all PHP files are ignored, but Blade files are formatted however you'd like.

Back to Posts