2

I am using Laravel 5.4 and Laravel Auditing 4.1. I want to record the price changes on Variant model, I installed the Auditing 4.1 package. See my code,

config/audit.php

'implementation' => OwenIt\Auditing\Models\Audit::class,

'user' => [
    'primary_key' => 'id',
    'foreign_key' => 'variant_id',
    'model'       => App\Variant::class,
    'resolver'    => App\Variant::class,
],

app/Models/Variant.php

use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

class Variant extends BaseModel implements AuditableContract{

   use Auditable;
 --------Code here----------------
}

Using this code when I try to insert data to database, This error will come,

 UnexpectedValueException
 Invalid User resolver, callable or UserResolver FQCN expected

How can I fix this error and record my changes on audits table?

Vinod VT
  • 6,946
  • 11
  • 51
  • 75
  • does your `App\User` model implements `OwenIt\Auditing\Contracts\UserResolver` interface? – Chay22 Nov 24 '17 at 19:25
  • @Chay22 When I implements this an error "Interface 'App\Models\OwenIt\Auditing\Contracts\UserResolver' not found" will get. I need to record the changes on variants table only. How can I do this? – Vinod VT Nov 25 '17 at 04:58
  • @VinodVT because PHP namespacing – lagbox Nov 26 '17 at 03:35

1 Answers1

1

This happens because the class (App\Variant::class) you configured in your config/audit.php to handle User resolution, does not implement the OwenIt\Auditing\Contracts\UserResolver contract.

So, if you really want to use App\Variant::class as your User resolver class, this is how it should look like:

<?php
namespace App;

use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

class Variant extends BaseModel implements AuditableContract, UserResolver
{
    use Auditable;

    public static function resolveId()
    {
        return Auth::check() ? Auth::user()->getAuthIdentifier() : null;
    }

    // More code here
}

When in doubt, have a look at the General Configuration documentation.

Quetzy Garcia
  • 1,820
  • 1
  • 21
  • 23