我正在用PHP Laravel 5写一个应用程序。我想在loginController中添加一个reverify函数,我在应用程序/邮件中添加了一个Reverify Reverify.php类,但是出现了这个错误:
Symfony \组件\调试\异常\ FatalThrowableError (E_ERROR)找不到“ APP \ Mail \ Reverify”类。
我已经完成过clear-compiled
和composer dump-autoload
的工匠工作,但是没有用。然后我在供应商/撰写者中检查了我的autoload_classmap.php,我可以看到
'App\\Mail\\Reverify' => $baseDir
。 '/app/Mail/Reverify.php'
,在其中。
这是我的 LoginController 代码。
<?php
namespace App\Http\Controllers\Auth;
use Mail;
use APP\Mail\Reverify;
class LoginController extends Controller {
...
...
Mail::to($email)-> send(new Reverify($confirmation_code));
...
...}
我的 Reverify.php 在应用程序/邮件中
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class Reverify extends Mailable
{
public $confirmation_code;
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
$this->confirmation_code = $confirmation_code;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject('XXXX: lock out')->view('reverify');
}
}
我的 autoload_classmap.php 在供应商/撰写者中
'App\\Mail\\Reverify' => $baseDir . '/app/Mail/Reverify.php'
这是我的错误日志
2019-02-25 02:42:50] local.ERROR: Class 'APP\Mail\Reverify' not found {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Class 'APP\\Mail\\Reverify' not found at /home/vagrant/code/x/app/Http/Controllers/Auth/LoginController.php:207)
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.1.3",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "5.5.*",
"doctrine/dbal": "~2.5"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~7.0",
"filp/whoops": "~2.1.10"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
答案 0 :(得分:3)
在 LoginController 中尝试更改
use APP\Mail\Reverify
至 use App\Mail\Reverify