laravel 找不到类“App\Http\Controllers\Hash”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49265888/
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
Class 'App\Http\Controllers\Hash' not found
提问by manix
I'm trying to use Hash in my global functions file.
我正在尝试在我的全局函数文件中使用 Hash。
I keep getting this error.
我不断收到此错误。
Class 'App\Http\Controllers\Hash' not found
找不到类“App\Http\Controllers\Hash”
where my file below is located at:
我的文件位于以下位置:
/app/Helpers/functions.php
/app/Helpers/functions.php
<?php
use App\Http\Controllers\Hash;
// If old password matches password
function checkOldPassword($oldPassword, $user) {
if (Hash::check($oldPassword, $user->password)) {
dd('a');
}
else {
return back()->withErrors([
'message' => 'Your old password is incorrect.'
]);
}
}
回答by manix
Hash
is a facade. It is working in your controller because has been imported correctly: use Hash;
However, in other classes or files, you need to import it as mentioned or using it without making an inclusion but backslash:
Hash
是一个门面。它在您的控制器中工作,因为已正确导入:use Hash;
但是,在其他类或文件中,您需要按照所述导入或使用它而不包含反斜杠:
<?php
// If old password matches password
function checkOldPassword($oldPassword, $user) {
if (\Hash::check($oldPassword, $user->password)) {
dd('a');
}
else {
return back()->withErrors([
'message' => 'Your old password is incorrect.'
]);
}
}
回答by Andrew Gillis
As the error helpfully points out, there is no class App\Http\Controllers\Hash
unless you created one. Remove that line your code should behave normally.
正如错误指出的那样,App\Http\Controllers\Hash
除非您创建了一个类,否则没有类。删除您的代码应该正常运行的那一行。