调用未定义的方法stdClass :: getModified()

时间:2019-02-03 19:13:36

标签: php laravel auditing laravel-auditing

Laravel v5.7.24
Laravel Auditing v8.0.4
PHP版本7.3.1

我有一个与软件包Laravel Auditing有关的特定问题。尽管我设置了Model以及文档中的所有内容,但刀片模板向我显示错误Call to undefined method stdClass::getModified()。非常感谢。

这是我的模特:

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');
    }
}

刀片视图:

<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>

1 个答案:

答案 0 :(得分:0)

鉴于错误消息(Call to undefined method stdClass::getModified()是针对stdClass而不是Audit的,我会做出一个疯狂的猜测,并假设您正在执行类似DB::table('audits')->where('auditable_type', Post::class)->get()的操作来获取审核,审核将以POPO实例而不是Audit实例的形式返回结果。

请尝试以下操作:Audit::where('auditable_type', Post::class)->get()