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

TonksM's avatar

Class "YamlFrontMatter" Not Found - Laravel, Docker, Composer

Recently, I've been following the "Laravel 8 From Scratch" Laracast, and chose to install Laravel using the Bash script installer method and running Laravel in a Docker container. I was happily following along until the instructor asked us to install YamlFrontMatter using Composer.

I opened the CLI for [project-name]_laravel.test_1, and ran the command: composer require spatie/yaml-front-matter. It seemed to install fine. So I returned to my code and tried to use the class in web.php as instructed, VSCode didn't complain, I then reloaded the webpage: 'Class "YamlFrontMatter" Not Found'.

So obviously, I think I need to import it with use, except, the instructor doesn't show that block of code, and I've tried every logical import I can think of ("use Vendor\Spatie\YamlFrontMatter" OR "use Spatie\YamlFrontMatter" OR "use YamlFrontMatter"), and I've also tried deleting the vendor folder & composer.lock file and reinstalling all the packages again, but to no avail. All produce the same error.

Can someone please help?

0 likes
12 replies
tykus's avatar
tykus
Best Answer
Level 104

The correct namespace alias in the top of your class is:

use Spatie\YamlFrontMatter\YamlFrontMatter;

Or use it as a fully-qualified class name inline in your code:

\Spatie\YamlFrontMatter\YamlFrontMatter::parse($yaml);
7 likes
Anas_debug's avatar

@tykus Thank you for the solution but I tried it both ways and it did not work for me perhaps it is something related to Laravel 9.

Sinnbeck's avatar

@Anas_debug If you are having issues, you should create a thread describing your issues, and we will gladly help

1 like
hxnshaw's avatar

@tykus Facing this exact problem currently. Still not working.

1 like
TonksM's avatar

Thank you! I just ended up figuring this out myself by installing PHPStorm (the IDE used in the demo) and seeing what it imported when I used the YamlFrontMatter in the file.

Looking at the YamlFrontMatter.php file again, it's blindingly obvious now.

Many thanks either way!

cverster's avatar

For "independent" classes like yaml, i would suggest you install them via composer with terminal in your VScode or PHPStorm, this will root the install in your current project.

3 likes
inocrypt's avatar

+title: null +excerpt: null +date: null +body: " "

my metadata is not coming

its episode 12 of (laravel 8 from scratch)

can someone help me

codeOnJim's avatar

For those who are using VSCode, and facing this issue. Even though the IDE screams that it can not recognize YamlFrontMatter, it works. Generally restarting the IDE worked for me.

2 likes
gBhatt1998's avatar

file_put_contents(C:\composer): Failed to open stream: Permission denied i am not able to install yaml front matter pls help

Please or to participate in this conversation.