首页 > 请教个 LaravelAutoPresenter 包 出现的问题

请教个 LaravelAutoPresenter 包 出现的问题

直接上图

上面的 $article 等于 php Article::find(1)

ArticleModel 和 UserModel 在model关联关系

ArticleModel

UserPresenter

然后在view里没法这样使用

//这种可以调用,
{{ $article->images() }}
//这种不可以调用,
{{ $article->author->byName() }}

还有个奇怪的现象...


在具体的 Presenter 中你需要使用

 $this->getWrappedObject() 

来获取当前 Presenter 绑定的 Model,因此你这里的代码需要改为:

public function byName()
{
    $this->getWrappedObject()->author()->nickName;
}

这样你就可以直接在 blade 模板中直接使用{{ $article->byName }}

【热门文章】
【热门文章】