Laravel v5.7.24
Laravel Auditing v8.0.4
PHP version 7.3.1
I've a specific problem related to package Laravel Auditing. Although I set the Model and everything like in documentation, the blade template is showing me an error Call to undefined method stdClass::getModified()
. Thank you so much.
Here's my Model:
namespace App;
use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;
class Post extends Model implements Auditable
{
use Searchable, \OwenIt\Auditing\Auditable;
protected $fillable = [...];
protected $auditExclude = [...];
public function user()
{
return $this->belongsTo('App\User');
}
}
Blade view:
<ul>
@forelse ($audits as $audit)
<li>
@foreach ($audit->getModified() as $attribute => $modified)
<ul>
<li>@lang('article.'.$audit->event.'.modified.'.$attribute, $modified)</li>
</ul>
@endforeach
</li>
@empty
<p>@lang('article.unavailable_audits')</p>
@endforelse
</ul>
Given that the error message (Call to undefined method stdClass::getModified()
) refers to stdClass
and not Audit
, I'll take a wild guess and presume you're doing something like DB::table('audits')->where('auditable_type', Post::class)->get()
to fetch the audits, which returns the results as POPO, not Audit
instances.
Try this instead: Audit::where('auditable_type', Post::class)->get()