Class App\Policies\StatusPolicy does not exist

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Resolving the Mystery: Why "Class App\Policies\StatusPolicy does not exist" Happens in Laravel Authorization

As developers move into more complex applications, implementing robust authorization is crucial. Laravel's built-in Policies feature, as detailed in the official documentation on Laravel Authorization, provides a clean, object-oriented way to manage permissions. However, setting up these policies often leads to frustrating errors like "Class does not exist," especially when defining controller middleware.

This post dives deep into why this specific error occurs and walks you through the exact steps needed to correctly configure your Policies so that Laravel's authorization system works as intended.

The Root Cause: Namespace and File Resolution

The error Class App\Policies\StatusPolicy does not exist almost always points to a mismatch between how you have defined the relationship in your AuthServiceProvider and the actual file structure or namespace of your policy class.

When Laravel attempts to resolve this path, it looks for a class file matching that exact namespace and class name within the application's structure. If the path specified in $policies doesn't exactly match the file system structure, the resolution fails.

Let’s review the potential failure points based on the setup you provided:

1. The AuthServiceProvider Mapping Check

Your configuration in AuthServiceProvider.php is:

protected $policies = [
    'App\Status' => 'App\Policies\StatusPolicy',
];

This tells Laravel: "When dealing with the App\Status Eloquent model, use the class located at App\Policies\StatusPolicy for authorization rules." This mapping is correct if the file exists exactly as specified.

2. The Policy File Structure Check

The error strongly suggests that even if you ran php artisan make:policy StatusPolicy --model=Status, the generated file might be in a different directory or have an incorrect namespace declaration. Ensure your policy file resides within the designated app/Policies directory and correctly defines its namespace.

If your policy is located at app/Policies/StatusPolicy.php, the class definition must start with namespace App\Policies;. If it starts with namespace Policies; (as seen in your example), Laravel cannot find it when resolving paths from the Service Provider.

Step-by-Step Solution and Best Practices

To resolve this issue, follow these steps to ensure perfect synchronization between your models, policies, and service provider:

Step 1: Verify Model and Policy Naming Convention

Ensure your Eloquent model (App\Status) exists and is correctly structured. Then, confirm your policy class adheres strictly to the Laravel convention:

Correct Structure:
If you are using the standard setup where models live in app/Models and policies in app/Policies, ensure your file structure matches the namespace you use in the service provider.

Step 2: Correcting the Policy Namespace

In your provided example, the policy defined:

namespace Policies; // <-- Potential problem area

This should be corrected to match the application's root namespace for full compatibility with Laravel's dependency injection system.

Corrected StatusPolicy.php Example:

namespace App\Policies; // Must match the path used in AuthServiceProvider!

use App\User;
use App\Status;
use Illuminate\Auth\Access\HandlesAuthorization;

class StatusPolicy
{
    use HandlesAuthorization;
    // ... methods remain the same
}

Step 3: Verifying Controller Middleware Syntax

The syntax in your StatusController middleware looks mostly correct, but ensure you are referencing the model name correctly within the can: statement.

$this->middleware('can:list,App\Status')

This assumes that the policy mapping correctly links the App\Status model to the rules defined in App\Policies\StatusPolicy. If the namespace fix above is implemented, this line should now resolve successfully, allowing Laravel to check the appropriate authorization rules.

Conclusion

The "Class does not exist" error in policy setups is rarely a bug in the logic of your policies themselves; it is almost always an issue of file system structure and namespace alignment within the service provider configuration. By strictly adhering to the expected directory structure (app/Policies) and ensuring that the namespace defined in every class matches the path specified in AuthServiceProvider, you establish a robust and predictable authorization layer. Always start by double-checking these foundational setup steps when working with Laravel's powerful features like Policies.