gpt4 book ai didi

php - Laravel - 未找到命名空间中的类

转载 作者:行者123 更新时间:2023-12-04 17:05:19 25 4
gpt4 key购买 nike

我有这个模型类(文件名是 Audit.php):

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

abstract class AuditStatus
{
const UNKNOWN = "UNKNOWN";
const ERROR = "ERROR";
const WARNING = "WARNING";
const MSG = "MESSAGE";

const EXCHANGE_UPDATE = "EXCHANGE_UPDATE";
const PRICE_UPDATE = "PRICE_UPDATE";
}

class AuditCodes extends AuditStatus
{
}

class Audit extends Model
{
use HasFactory;

public $timestamps = false;

protected $fillable = ['action', 'msg'];

public static function Add($action, $msg){
(new static)::insert(['action'=>$action, 'msg' => $msg]);
}
}
我正在尝试创建一个这样的新命令:
<?php

namespace App\Console\Commands;

use App\Models\AuditCodes;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class PriceCreate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'price:create';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create prices';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
dd(AuditCodes::MSG);
}
}
但是当我运行命令时,编译器会抛出这个错误:
 Error

Class "App\Console\Commands\App\Models\Audit\Audit_Codes" not found

at C:\xampp\htdocs\bintest\app\Console\Commands\PriceCreate.php:46
任何人都可以帮助我如何声明我的类(class)吗?
谢谢!!!

最佳答案

尝试在自己的文件中声明每个类。
我的意思是如果你有三个类:Audit、AuditCodes 和 AuditStatus
您还将在 App\Models\ 中拥有三个不同的文件目录,就像这样 App\Models\Audit.php , App\Models\AuditCodes.phpApp\Models\AuditStatus.php .
应该可以解决你的问题。

关于php - Laravel - 未找到命名空间中的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70059540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com