laravel - 流明:从模型文件调用特征帮助文件不起作用
问题描述
我在我的模型文件中使用我的特征文件“CommonTrait”,如下所示,
在命名空间中使用,
use App\Http\Helpers\CommonTrait;
在课堂内使用,
class LoginHistory extends Model
{
use CommonTrait;
//use inside function as
protected static function getList($req)
{
$reportFilter= $this->searchCommonFilter($reportDateFilter, $req);
//this is my trait function
}
}
但它给了我这样的错误
Using $this when not in object context
解决方案
您正在从静态函数访问方法,这就是错误消息的含义,您可以使用static::function() or static::property
.
在您的情况下,该函数似乎不是静态的,您需要从函数中删除静态声明或将您正在调用的函数设为静态函数。
推荐阅读
- java - 关于约束布局的问题
- mongodb - 如何使用用户管理方法和 pymongo 在 MongoDB 中通过 UserId 查询用户
- hibernate - 有没有办法在 JPA/Hibernate 的 java doc 中包含 db 列名?
- html - 本地主机上的 iframe 标记和烧瓶项目的本地 html 文件中没有内容(在 mac 上的 vs 代码中)
- user-interface - 如何使用空手道 UI 向右/向左滚动?
- firebase - 很少有 Android 的 app_update 事件
- php - 如何显示像 1.1k 而不是 1100 这样的数字
- javascript - 使 React 与 math.js 库一起工作
- python - 如何在字典中的枚举中添加文档字符串
- c# - 如何使用 DeserializeObject 方法处理空值