title: How To fetch last id from database in laravel4
body: <p>I am trying to fetch value from database to my web page.
  My database table <strong>WysTeachermessage</strong></p>
  
  <pre><code>id sendname  replyname     message    stop_id    start_id
  
  1   x           y            hai           2          1
  
  2   y           x            hai           2          1
  </code></pre>
  
  <p>I want only last message from this table</p>
  
  <pre><code>id sendname    replyname   message    stop_id    start_id
  
  2   y              x          hai           2          1
  </code></pre>
  
  <p>I am using controller code </p>
  
  <pre><code>$send_stop=['sendname'=&gt;x,'replyname'=&gt;y,'stop_id'=&gt;2,'start_stop'=&gt;1];
        $receiver_stop=['replyname'=&gt;x,'sendname'=&gt;y,'stop_id'=&gt;2,'start_id'=&gt;1];
        $teacherinboxes=WysTeachermessage::where($send_stop)
                                          -&gt;orWhere($receiver_stop)
                                          -&gt;orWhere('stop_id',0)
                                          -&gt;orderBy('id','desc')
                                          -&gt;get();
  </code></pre>
  
  <p>How to fetch last id values from database.??</p>
  
  <p>my controller code </p>
  
  <p><code>$adm_msg=array();
          foreach($students as $student)
          {
            $send_stop=['student_id'=&gt;$student-&gt;id,'receiver_id'=&gt;$userid];
            $receiver_stop=['student_id'=&gt;$student-&gt;id,'sender_id'=&gt;$userid];
            $parent_messages=WysMessage::where($send_stop)
                                          -&gt;orWhere($receiver_stop)
                                           -&gt;orderBy('id','desc')
                                          -&gt;first();
              $adm_msg[$student-&gt;id] = $parent_messages['send_msg'];
           }
           $students=WysStudent::all(); 
           $parent =WysParent::all();
           $clss = DB::table('wys_classes')
                -&gt;join('wys_classnames', 'wys_classes.cls', '=', 'wys_classnames.id')
                -&gt;join('wys_divnames', 'wys_classes.divn', '=', 'wys_divnames.id')
                -&gt;select('wys_classes.id', 'wys_classnames.classname', 'wys_divnames.divname')
                -&gt;get();
            $send_stop=['receiver_id'=&gt;$userid,'parent_stop_id'=&gt;1,'teacher_stop_id'=&gt;0];
            $receiver_stop=['sender_id'=&gt;$userid,'parent_stop_id'=&gt;0,'teacher_stop_id'=&gt;0];
            $recv_stop=['receiver_id'=&gt;$userid,'parent_stop_id'=&gt;0,'teacher_stop_id'=&gt;0];
            $send_admin=['sender_id'=&gt;$userid,'parent_stop_id'=&gt;1,'teacher_stop_id'=&gt;0];
            $parent_messages=WysMessage::where($send_stop)
                                        -&gt;orWhere($receiver_stop)
                                        -&gt;orWhere($send_admin)
                                        -&gt;orWhere($recv_stop)
                                        -&gt;orderBy('id','desc')
                                        -&gt;get();</code></p>