Maaz Zindani

Loading the index…

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

Laravel controller says the Redirect class is not found

ErrorClass "App\Http\Controllers\Redirect" not found

Short answer

PHP looks for Redirect inside the controller's own namespace because the file never imports the facade. Add use Illuminate\Support\Facades\Redirect; at the top of the file, or call the redirect() helper, which needs no import. Facades only live in the Illuminate\Support\Facades namespace.

  • Applies to PHP 8.3, Laravel 12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    The class name in the message starts with your own namespace. That tells you PHP found no import for it. Check the top of the file for a use line.

    grep -n "Redirect" app/Http/Controllers/*.php
  2. 2Match what you see, then jump to its fix

    1. 1Class "App\Http\Controllers\Redirect" not found, at a line with Redirect::to() or Redirect::route().The Redirect facade is used but never importedFix
    2. 2The message names a class under another namespace, such as Illuminate\Support\Redirect or Illuminate\Http\Redirect.The facade is imported from a namespace that does not existFix

What does the error look like?

  • Class "App\Http\Controllers\Redirect" not found
  • Class 'App\Http\Controllers\Redirect' not found

Cause 1 of 2

The Redirect facade is used but never imported

1Check

In a namespaced file, a bare class name resolves inside that namespace. Laravel defines every facade in Illuminate\Support\Facades, so a controller must import it.

sed -n 1,15p app/Http/Controllers/PostController.php

2Fix

Import the facade, or use the redirect() helper. The docs say a facade and its helper function are equivalent, and the helper needs no import.

use Illuminate\Support\Facades\Redirect;

return Redirect::route('posts.index');

// or, with no import
return redirect()->route('posts.index');

3Verify

Request the route that returns the redirect and follow the Location header.

curl -I http://localhost:8000/posts/create

Confirmed by laravel.com

Did this fix it?

Cause 2 of 2

The facade is imported from a namespace that does not exist

1Check

An editor auto-import or a copied snippet can pick the wrong namespace. The class behind the Redirect facade is Illuminate\Routing\Redirector, and the facade itself is in Illuminate\Support\Facades.

grep -rn "use .*Redirect" app/

2Fix

Replace the import with the facade's real namespace.

use Illuminate\Support\Facades\Redirect;

3Verify

No wrong import remains and the page loads.

grep -rn "use .*Redirect" app/

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Prefer the redirect() helper in controllers; it cannot hit this error.
  • Let the IDE add imports, but read the namespace it picks before accepting it.
  • Run a static analyser in CI so unknown classes fail the build.

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.