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);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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?
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);
Please or to participate in this conversation.