Laravel 4 如何在laravel4中从数据库中获取最后一个id

Laravel 4 如何在laravel4中从数据库中获取最后一个id,laravel-4,Laravel 4,我正在尝试从数据库中获取值到我的网页。 “我的数据库表”消息 我只想要这张桌子上的最后一条消息 id sendname replyname message stop_id start_id 2 y x hai 2 1 我正在使用控制器代码 $send_stop=['sendname'=>x,'replyname'=>y,'stop_id'=>2,'start_stop

我正在尝试从数据库中获取值到我的网页。 “我的数据库表”消息

我只想要这张桌子上的最后一条消息

id sendname    replyname   message    stop_id    start_id

2   y              x          hai           2          1
我正在使用控制器代码

$send_stop=['sendname'=>x,'replyname'=>y,'stop_id'=>2,'start_stop'=>1];
      $receiver_stop=['replyname'=>x,'sendname'=>y,'stop_id'=>2,'start_id'=>1];
      $teacherinboxes=WysTeachermessage::where($send_stop)
                                        ->orWhere($receiver_stop)
                                        ->orWhere('stop_id',0)
                                        ->orderBy('id','desc')
                                        ->get();
如何从数据库中获取最后一个id值

我的控制器代码

$send_stop=['sendname'=>x,'replyname'=>y,'stop_id'=>2,'start_stop'=>1];
      $receiver_stop=['replyname'=>x,'sendname'=>y,'stop_id'=>2,'start_id'=>1];
      $teacherinboxes=WysTeachermessage::where($send_stop)
                                        ->orWhere($receiver_stop)
                                        ->orWhere('stop_id',0)
                                        ->orderBy('id','desc')
                                        ->get();
$adm_msg=数组; foreach$student作为$student { $send\u stop=['student\u id'=>$student->id,'receiver\u id'=>$userid]; $receiver\u stop=['student\u id'=>$student->id,'sender\u id'=>$userid]; $parent_messages=WysMessage::where$send_stop ->或者$receiver\u停在哪里 ->orderBy'id','desc' ->第一,; $adm_msg[$student->id]=$parent_messages['send_msg']; } $students=WysStudent::all; $parent=WysParent::all; $clss=DB::表“wys\U类” ->加入'wys_classnames','wys_classnames.cls','=','wys_classnames.id' ->加入'wys_divnames'、'wys_classes.divn'、'='、'wys_divnames.id' ->选择'wys_classes.id','wys_classnames.classname','wys_divnames.divname' ->得到; $send\u stop=['receiver\u id'=>$userid,'parent\u stop\u id'=>1,'teacher\u stop\u id'=>0]; $receiver\u stop=['sender\u id'=>$userid,'parent\u stop\u id'=>0,'teacher\u stop\u id'=>0]; $recv\u stop=['receiver\u id'=>$userid,'parent\u stop\u id'=>0,'teacher\u stop\u id'=>0]; $send_admin=['sender_id'=>$userid,'parent_stop_id'=>1,'teacher_stop_id'=>0]; $parent_messages=WysMessage::where$send_stop ->或者$receiver\u停在哪里 ->或在何处$send_admin ->或者$recv_停在哪里 ->orderBy'id','desc'
->得到

只需先使用,而不是获取

$teacherinboxes=WysTeachermessage::where($send_stop)
                                    ->orWhere($receiver_stop)
                                    ->orWhere('stop_id',0)
                                    ->orderBy('id','desc') 
                                    ->first(); // use first() instead of get()

我也认为是代码,但它不起作用。。因为sendnamex将消息发送给另一个onez,如果使用此代码无效,则停止id=0。在$send\u stop中,您在那里写了“start\u stop”,这是打字错误吗?还是应该改为“启动id”?您能提供更多关于什么是停止id和启动id的解释吗?先生,完整的控制器代码在上面…我想给您一个我的代码示例。家长\u停止\u id和教师\u停止\u id作为停止\u id和开始\u id。我需要$send\u stop和$send\u admin检查,然后其真实值仅显示上表类似的最后一个值。