在 laravel 5.4 中找不到致命可抛掷错误类"应用程序\模型\患者"



我使用命令php artisan make:model Patient创建了一个模型。该命令在应用文件夹中创建名为Patient的模型。

在模型患者中:

namespace App;
use IlluminateDatabaseEloquentModel;
class Patient extends Model
{
//
public function getPurchaseOrder(){
return "Hello World";        
}
}

在控制器中 患者控制器:

namespace AppHttpControllers;
class PatientController extends Controller
{
protected $patientModel;
public function __construct(Request $request, PatientInterface $patient)
{
parent::__construct($request);        
$this->patientModel = new AppPatient();
}
public function test(){
echo $this->patientModel->getPurchaseOrder();
}
}

它工作正常。问题是当我在应用程序文件夹中创建一个名为Models的文件夹并移动患者模型然后调用模型函数时,它会给出错误:

FatalThrowableError Class 'AppModelsPatient' not found

任何帮助将不胜感激。

将类移动到其他目录时,要由作曲家使用 PSR-4 标准加载该类,还必须更新类的命名空间以匹配。

namespace AppModels;

此外,当您运行 make 命令时,您可以在其中包含一个命名空间,以自动将其放入具有正确命名空间的目录中:

php artisan make:model Models\Patient

相关内容

最新更新