hetal gohel
hetal gohel

Reputation: 355

Lumen: Call trait helper file from model file not working

I am using my trait file "CommonTrait" inside my model file as below,

use in namespace,

use App\Http\Helpers\CommonTrait;

use inside class,

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
   }
}

but it gives me error like

Using $this when not in object context

Upvotes: 0

Views: 398

Answers (1)

Shobi
Shobi

Reputation: 11461

you are accessing a method from a static function, that's what the error message means, you can call other static functions/properties using static::function() or static::property.

In your case the function does not seems to be static, you need to either remove the static declaration from the fuinction or make the function which you are calling to a static one.

Upvotes: 1

Related Questions