| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | no
| Framework | Laravel
| Framework version | 5.8.36
| Package version | 9.3.2
| PHP version | 7.2.26
Any operation that uses the Audit events fails with an exception:
Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given
I'm expecting the library to just work.
I simply have a model that implements \OwenIt\Auditing\Contracts\Auditable and uses OwenIt\Auditing\Auditable, and I try to save records on it via Eloquent. Nothing fancy.
Trying to debug, I found out that the compileInsert function in Illuminate\Database\Query\Grammars\Grammar.php tries o determine if the $values input is an array of records (arrays) or if it is a single record (array). In the second case, it wraps it in a array,
My $values variable is something like this, when I try to insert a record:
(
[old_values] => Array
(
)
[new_values] => Array
(
[name] => 3332
[birth_date] => 2020-01-30
[sw_version] => 32
[part_no] => 13
[serial_no] => 654765te5
[category_id] => 5
[type_id] => 2
[attributes_json] => {"tot_km":null,"old_km":[],"old_sw":[{"sw":"32","date":"01-2020"}]}
[id] => 140
)
[event] => created
[auditable_id] => 140
[auditable_type] => App\Http\Models\SystemElements
[user_id] => 1
[user_type] => App\Http\Models\User
[url] => http://gimmi-skg.local/system_elements?train_id=1
[ip_address] => 192.168.10.1
[user_agent] => Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0
[tags] =>
[updated_at] => 2020-01-30 12:58:09
[created_at] => 2020-01-30 12:58:09
)
Being the first value an array, the function believes that $values is not a single record, and does not wrap it. When the same function later tries to parametrize each elements of $values it fails on the first non-array element (`'event' => 'created').
Probably old_values and new values should be json strings at this point.
Worked it around by adding:
protected $casts = [
'old_values' => 'json',
'new_values' => 'json',
];
to the Audits model. Didn't understand why it needs it, tho.
butwith arabic chars return as u0627u0644u0645u0642u064au064au064a
@lBreda u saved my day!
Most helpful comment
Worked it around by adding:
to the Audits model. Didn't understand why it needs it, tho.