laravel 致命错误:找不到类“App\Http\Controllers\Redirect”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39892503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:32:19  来源:igfitidea点击:

Fatal error: Class 'App\Http\Controllers\Redirect' not found

laravellaravel-5laravel-5.2laravel-5.1

提问by Milan Suthar

when i run below command in my terminal it shows below code instead of routes

当我在终端中运行下面的命令时,它显示下面的代码而不是路由

php artisan route:list



 <html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="1;url=http://localhost/login" />

        <title>Redirecting to http://localhost/login</title>
    </head>
    <body>
        Redirecting to <a href="http://localhost/login">http://localhost/login</a>.
    </body>
</html>

[Symfony\Component\Debug\Exception\FatalThrowableError] Fatal error: Class 'App\Http\Controllers\Redirect' not found

[Symfony\Component\Debug\Exception\FatalThrowableError] 致命错误:找不到类“App\Http\Controllers\Redirect”

采纳答案by haakym

You can't run php artisan route:listif any of the routes and their related controllers have errors.

php artisan route:list如果任何路由及其相关控制器有错误,您将无法运行。

In this case, it looks like you have a controller that has an error which is that you're using the Redirectfacade without importing it first, so it's looking for the Redirectclass in the same namespace as the controller, i.e. App\Http\Controllers\Redirect.

在这种情况下,看起来您的控制器有一个错误,即您在使用Redirect外观时没有先导入它,因此它正在Redirect与控制器相同的命名空间中查找类,即App\Http\Controllers\Redirect.

Locate the class that is using the Redirectfacade and add Use Redirectto the top of the file and that should sort it hopefully!

找到使用Redirect门面的类并添加Use Redirect到文件的顶部,这应该对它进行排序!

回答by Filip Koblański

The only thing that you have to do is to add:

您唯一需要做的就是添加:

use Redirect;

in your controller just after namespaceline or put \before you call Redirect::i.e.:

在您的控制器中就在namespace线路之后或\在您致电之前放置,Redirect::即:

return \Redirect::back();

回答by gauravbhai daxini

You have to import the class. This is the one you need:

您必须导入该类。这是你需要的:

use Illuminate\Support\Facades\Redirect;

回答by A.N

Add \before Redirect the function

\在重定向函数之前添加

return \Redirect::back();

返回 \Redirect::back();

It works fine for me in laravel 5.3

它在 Laravel 5.3 中对我来说很好用