首页 > 解决方案 > 流明:从模型文件调用特征帮助文件不起作用

问题描述

我在我的模型文件中使用我的特征文件“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

标签: laravelmodellumen

解决方案


您正在从静态函数访问方法,这就是错误消息的含义,您可以使用static::function() or static::property.

在您的情况下,该函数似乎不是静态的,您需要从函数中删除静态声明或将您正在调用的函数设为静态函数。


推荐阅读