dqhr76378 2014-09-01 08:35
浏览 72

从数据库获取最新版本的帖子

I am creating a blog where users can post and other users can edit there posts.

When someone edits a post the version should be updated and saved, this works.

Now I want to display only the latest version to the readers.

Not 100% sure how this should work.

I created a function within the model that would select the version based on a simple MAX query. Here is the model:

public function getlatestversion(){
        $lastest = DB::table('contentPost')->max('version');

        return $this->$lastest;
    }

My Blade View:

Partial:

 {{ Str::limit($post->content_posts()->getlatestversion()['content'], 140) }} 

Can I use this directly in my blade view? Or should it also be in my controller? The error that I get is:

"Call to undefined method... getlatestversion()"

Does it have something to do that it is not in my controller, or am I passing it the wrong way?

Thanks

  • 写回答

1条回答 默认 最新

  • doupu5941 2014-09-01 08:42
    关注

    You are obviously in a context, where your method content_posts() does not retrieve a working reference to an object featuring the getlatestverison() method.

    Try printr()-ing the result of $post->content_posts() - this might give you a precise hint why you cannot access your method.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据