I have two tables related with a many-to-many relationship by a pivot table, conversations_user. I have this working fine in my controller :
Controller
public function create()
{
$loginuser = User::find(Auth::user()->id);
$user_id = $loginuser->id;
$conversations = $loginuser->conversations;
return View::make('brightcms.Conversations.Conversations',array('user_id'=>$user_id,'conversations'=>$conversations));
}
Now I want to get the conversations arranged in descending order according to a created_at
column in the conversations table + reverse() . I tried :
$conversations = $loginuser->conversations->orderBy('created_at','desc')->get()->reverse();
but it returns an error message. Thank you!