其中一个 service 类总是报 class not found 错误
最近新增了一个service类,报错:Class 'app\Services\SuspendService' not found。同目录中的其他service类运行正常。把我能想到的检查都做了,依然报错,请问下还有那些地方可能存在问题的:
1、用搜索方式检查类名,
2、更换使用方式,即注入方式和手工 new 的方式
3、逐步精简service类的代码,直至如下。
4、删除文件,重新创建: touch app/Services/SuspendService.php
5、从正常文件中复制下面代码的内容
6、Controller 类中去掉 Service 类后,Controller 类运行正常。
7、全文搜索正常的 service 类,查看是否有系统文件中有设置或者啥定义的地方,没找到奇怪的地方。
use app\Services\SuspendService;
class SuspendsController extends Controller
{
protected $suspendService;
// 1、注入方式
// public function __construct(SuspendService $suspendService)
// {
// $this->suspendService = $suspendService;
// }
public function update(Request $request){
//2、手工new的方式
$service = new SuspendService();
}
}
<?php
namespace App\Services;
class SuspendService
{
public function __construct(){
}
}
推荐文章: