Search code examples
laravelcartalyst-sentinellaravel-auditing

Non-static method Cartalyst\Sentinel\Sentinel::getUser() should not be called statically


Hi I am using laravel Sentinel as my Auth, also I am trying to use laravel auditing I am getting "Non-static method Cartalyst\Sentinel\Sentinel::getUser() should not be called statically".

In my user model I have added a static function resolveId() for adding user_id in Laravel Auditing 'audits' table

public static function resolveId(){
    return Sentinel::getUser()->getUserId();
    //return auth()->check() ? auth()->user()->getAuthIdentifier() : null;
}

When I try to use \Sentinel::getUser() I am getting the error below.

Non-static method Cartalyst\Sentinel\Sentinel::getUser() should not be called statically

Solution

  • From the docs:

    After installing the package, open your Laravel config file located at config/app.php and add the following lines. In the $aliases array add the following facades for this package.

    'Sentinel' => Cartalyst\Sentinel\Laravel\Facades\Sentinel::class,
    

    Then just add this to the top of the class:

    use Sentinel;