vendredi 7 juillet 2017

Laravel show last reply left on post

I'm trying to show the last reply that was left on a post. But only the name and date of it. I tried the following things

What I think this one should do is look at the replies to the post. Sort them by ID and then display the first one's username. But it doesn't work. $topic->replies->sortBydesc('id')->first()->user->username }}

I also tried this one where I requested all the replies in the entire forum and displayed the last one. It worked but I wasn't the one related to the post.

Does anyone know how I can make this work? Currently, i'm passing these two into the view (There is nothing wrong with these, they work but I think there should be something added)

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

Thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire