Laravel-审计工作没有任何错误

Laravel-Auditing is not working without any errors

我最近安装了 this 软件包,并使用指南配置了所有内容,但有些无法正常工作! 它不起作用我的意思是它没有向数据库添加任何内容。我真的不知道我的配置有什么问题,但我已经用指南检查了所有内容 3 次,一切都是正确的,但是...我不知道

config/audit.php:

<?php

return [

    'enabled' => env('AUDITING_ENABLED', true),

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

    'user' => [
        'morph_prefix' => 'user',
        'guards'       => [
            'web',
            'api',
        ],
    ],

    'resolver' => [
        'user'       => OwenIt\Auditing\Resolvers\UserResolver::class,
        'ip_address' => OwenIt\Auditing\Resolvers\IpAddressResolver::class,
        'user_agent' => OwenIt\Auditing\Resolvers\UserAgentResolver::class,
        'url'        => OwenIt\Auditing\Resolvers\UrlResolver::class,
    ],

    'events' => [
        'created',
        'updated',
        'deleted',
        'restored',
        'gold_mailed' => 'goldMailed',
        'invited' => 'clientInvited',
    ],

    'strict' => false,

    'timestamps' => false,

    'threshold' => 0,

    'driver' => 'session',

    'drivers' => [
        'eloquent' => [
            'table'      => 'audits',
            'connection' => null,
        ],
    ],

    'console' => true,
];

我要审核的模型:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;

use App\Models\Expansion;
use App\Models\Audit;

class Setting extends Model implements Auditable
{
    protected $table = 'settings';

    use \OwenIt\Auditing\Auditable;


    protected $fillable = [
      'expansion_id', 'season', 'advertiser_app', 'pvp_app', 'raid_app', 'version'
    ];

    protected $auditInclude = [
       'expansion_id', 'season', 'advertiser_app', 'pvp_app', 'raid_app', 'version'
   ];

    public function Expansion()
    {
      return $this->hasOne(Expansion::class, 'id', 'expansion_id');
    }
}

web.php:

Route::post('/setting' , 'Admin\SuperAdminController@saveSetting')->middleware('superadmin')->name('admin_save_setting');

控制器:

public function saveSetting(Request $request)
  {
    $sql = Setting::where('id', 1)->update([
      'expansion_id' => $request['expansion_id'],
      'season' => $request['season'],
      'advertiser_app' => $request['advertiser_app'],
      'pvp_app' => $request['pvp_app'],
      'raid_app' => $request['raid_app'],
      'version' => $request['version']
    ]);
    if ($sql) {
      toastr()->success('Settings successfully updated.');
      return redirect()->back();
    }
    toastr()->error('Something went wrong!');
    return redirect()->back();
  }

我不知道你需要什么信息,但我认为这就足够了

我认为我的问题是配置文件中的“驱动程序”,我不知道这是否正确

[更新]

根据您显示的控制器代码,它不起作用,因为您的代码是使用 Builder 样式调用的,并且该程序包仅在使用 Eloquent 样式调用时才有效。

Documentation link

所以,也许您需要将代码更改为:

$setting = Setting::where('id', 1)->firstOrFail();
$setting->update([
  'expansion_id' => $request['expansion_id'],
  'season' => $request['season'],
  'advertiser_app' => $request['advertiser_app'],
  'pvp_app' => $request['pvp_app'],
  'raid_app' => $request['raid_app'],
  'version' => $request['version']
]);

现在我有另一个问题-_-

这是我的控制器:

$sql = Raid::findOrFail($request['id']);
$sql = $sql->update($request->all());

我的 table 中有一个数组,更新后的值将是这样的:

"{\"Plate\":0,\"Cloth\":0,\"Mail\":0,\"Leather\":0}"

但应该是:

{"Plate":"0","Cloth":"0","Mail":"0","Leather":"0"}

所以我会得到一个错误 在此之前,我是这样更新的,没问题:

$sql = Raid::where('id', $request['id'])->update($request->all());

这是我的模式(交易者和 class_traders 是我遇到问题的领域):

    use SoftDeletes;

    use \OwenIt\Auditing\Auditable;

    protected $table = 'raid';

    protected $dates = ['date_and_time','deleted_at'];

    protected $fillable = [
      'admin_id', '....
    ];

    protected $casts = [
        'bosses' => 'array',
        'traders' => 'array',
        'class_traders' => 'array',
        'boosters' => 'array',
    ];