Rainieren
2 years ago

Laravel get latest reply from topic

Posted 2 years ago by Rainieren

Hello, I'm trying to display the latest post's username and date. I used something similar by using. Something along the lines of {{ topic->replies->sortBydesc('id')->first->user->username}} It makes sense to me. I also used something like $Allreplies which I defined in the controller with $allposts = Reply::all(); but that gets me ALL the replies of the entire forum and that's not what I want, It needs to display the latest reply of that particular topic.

Can someone tell me how to do this? My Controller looks like this

public function show($id)
    {

        $topics = Topic::with('theme')->find($id);
        $theme = Theme::with('topics')->find($id);

        return view('themes.theme')->with('topics', $topics)->with('theme', $theme);
    }

Please sign in or create an account to participate in this conversation.