for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Hamidrezaniazi\Laramist\Models;
use Hamidrezaniazi\Laramist\Guard;
use Illuminate\Contracts\Auth\Authenticatable as User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class ModelHistory extends Model
{
protected $guarded = ['id'];
protected $casts = [
'changed' => 'array',
];
/**
* @return MorphTo
*/
public function subject(): MorphTo
return $this->morphTo();
}
* @return BelongsTo
public function causer(): BelongsTo
return $this->belongsTo(Guard::getGuardClassName(), 'causer_id');
* @param Model $subject
* @param User|null $user
* @return void
public static function logChanges(Model $subject, ?User $user): void
if ($subject->wasChanged()) {
$changed = $subject->getChanges();
unset($changed['updated_at']);
$history = new self();
$history->subject()->associate($subject);
$history->causer()->associate($user);
$user
object<Illuminate\Contra...h\Authenticatable>|null
object<Illuminate\Databa...t\Model>|integer|string
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
$history->changed = $changed;
$history->save();
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: