应用程序\常数\ ProductConstant.php
<?php
namespace App\Constant;
use App\Constant\BaseConstant;
class ProductConstant extends BaseConstant {
const TITLE = "title";
}
Product.php
<?php
namespace App\Models;
use App\Constant\ProductConstant;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $table = 'products';
protected $fillable = [ProductConstant::TITLE, ProductConstant::IMAGE, ProductConstant::EXPIRY_DATE, ProductConstant::MAX_PARTICIPANTS, ProductConstant::TOTAL_PARTICIPANTS];
错误
未定义的类常量'App \ Constant \ ProductConstant :: TITLE'
在我执行了php artisan config:clear
之后。我可以知道是什么原因吗?
不要在本地系统中运行php artisan config:clear
,它可能会破坏你的项目
删除此文件bootstrap/cache/config.php
并再次运行项目
运行php artisan cache:clear
清除.env文件的缓存