Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel says the class Laravel\Fortify\Features cannot be found

ErrorError Class "Laravel\Fortify\Features" not found

Short answer

Laravel\Fortify\Features is a class inside the laravel/fortify package, and config/fortify.php imports it. When PHP cannot load it, either the package is not in vendor/ (never required, or skipped by --no-dev), or the autoloader cannot map the name (a stale authoritative classmap, or a name spelled with the wrong letter case on Linux).

  • Applies to Laravel 12, Fortify 1.x, PHP 8.3, Composer 2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the disk whether the class file is there. If the file is missing, the package is not installed here. If it is there, the autoloader is the problem.

    ls vendor/laravel/fortify/src/Features.php
    grep -n "fortify" composer.json
  2. 2Match what you see, then jump to its fix

    1. 1ls reports no such file, and composer.json has no laravel/fortify linelaravel/fortify was never installed in this projectFix
    2. 2It works on your machine and fails only after a deploy that runs composer install --no-devThe package sits in require-dev and production installs with --no-devFix
    3. 3The file exists under vendor/laravel/fortify/src, yet the check prints bool(false), and the deploy script uses --classmap-authoritative or -aAn authoritative classmap was built before the package was addedFix
    4. 4The app works on macOS or Windows and fails on a Linux server or in DockerThe name is spelled with different letter case and the server is LinuxFix

What does the error look like?

  • Error Class "Laravel\Fortify\Features" not found
  • Class "Laravel\Fortify\Features" not found

Cause 1 of 4

laravel/fortify was never installed in this project

1Check

config/fortify.php (or app/Providers/FortifyServiceProvider.php) can exist without the package. That happens when files are copied from another project, or a branch is merged without its composer.json change. Fortify is a separate Composer package, not part of the framework.

composer show laravel/fortify
ls config/fortify.php app/Providers/FortifyServiceProvider.php

2Fix

Require the package. If composer.json already lists it and only vendor/ is stale, composer install is enough.

composer require laravel/fortify
# only when composer.json and composer.lock already list it:
composer install

3Verify

Fortify registers its routes once it loads, so route:list now shows them and the class error is gone.

php artisan route:list

Confirmed by laravel.com

Did this fix it?

Cause 2 of 4

The package sits in require-dev and production installs with --no-dev

1Check

--no-dev skips every package under require-dev. If laravel/fortify is listed there, the production vendor/ folder never receives it, while config/fortify.php still imports its class.

grep -n -E '"require(-dev)?"|laravel/fortify' composer.json

2Fix

Move the laravel/fortify line from require-dev into require in composer.json, then update just that package so composer.lock follows. Commit both files and deploy again.

composer update laravel/fortify
composer install --no-dev

3Verify

The class file now exists in a no-dev install.

ls vendor/laravel/fortify/src/Features.php

Confirmed by getcomposer.org

Did this fix it?

Cause 3 of 4

An authoritative classmap was built before the package was added

1Check

With an authoritative classmap Composer trusts the map only: a class that is not in it does not exist, and the PSR-4 folders are never searched. A map generated before Fortify arrived has no entry for it.

grep -rn -E "classmap-authoritative|optimize-autoloader" composer.json Dockerfile 2>/dev/null
php -r 'require "vendor/autoload.php"; var_dump(class_exists("Laravel\\Fortify\\Features"));'

2Fix

Regenerate the autoloader with the same flags your deploy uses. Do this on every deploy, after composer install.

composer dump-autoload --classmap-authoritative

3Verify

PHP can now load the class, so the check prints bool(true).

php -r 'require "vendor/autoload.php"; var_dump(class_exists("Laravel\\Fortify\\Features"));'

Confirmed by getcomposer.org

Did this fix it?

Cause 4 of 4

The name is spelled with different letter case and the server is Linux

1Check

PHP class names ignore case, but PSR-4 maps a name to a file path, and Linux file systems do not. A line such as use Laravel\Fortify\features; asks for src/features.php, which does not exist. List how the name is written in your own code.

grep -rn -i 'fortify\\features' config app routes bootstrap

2Fix

Write the name exactly as the package spells it: Laravel\Fortify\Features, with the capital letters shown.

<?php

use Laravel\Fortify\Features;

3Verify

Fortify loads again, and its routes show up in the list.

php artisan route:list

Confirmed by php-fig.org

Did this fix it?

How do I stop it coming back?

  • Commit composer.lock together with composer.json, and run composer install (not update) on servers.
  • Keep packages that config files import in require, never in require-dev.
  • Run composer dump-autoload with the same flags in every deploy, right after composer install.
  • Develop on a case-sensitive file system (Linux container or Sail), so spelling mistakes show up before release.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.