久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='fcZkP'></tfoot>

    <small id='fcZkP'></small><noframes id='fcZkP'>

      <i id='fcZkP'><tr id='fcZkP'><dt id='fcZkP'><q id='fcZkP'><span id='fcZkP'><b id='fcZkP'><form id='fcZkP'><ins id='fcZkP'></ins><ul id='fcZkP'></ul><sub id='fcZkP'></sub></form><legend id='fcZkP'></legend><bdo id='fcZkP'><pre id='fcZkP'><center id='fcZkP'></center></pre></bdo></b><th id='fcZkP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fcZkP'><tfoot id='fcZkP'></tfoot><dl id='fcZkP'><fieldset id='fcZkP'></fieldset></dl></div>
      • <bdo id='fcZkP'></bdo><ul id='fcZkP'></ul>

    1. <legend id='fcZkP'><style id='fcZkP'><dir id='fcZkP'><q id='fcZkP'></q></dir></style></legend>
    2. laravel Eloquent ORM delete() 方法

      laravel Eloquent ORM delete() method(laravel Eloquent ORM delete() 方法)

          <legend id='b8Cbp'><style id='b8Cbp'><dir id='b8Cbp'><q id='b8Cbp'></q></dir></style></legend>

          <small id='b8Cbp'></small><noframes id='b8Cbp'>

            • <bdo id='b8Cbp'></bdo><ul id='b8Cbp'></ul>
              <i id='b8Cbp'><tr id='b8Cbp'><dt id='b8Cbp'><q id='b8Cbp'><span id='b8Cbp'><b id='b8Cbp'><form id='b8Cbp'><ins id='b8Cbp'></ins><ul id='b8Cbp'></ul><sub id='b8Cbp'></sub></form><legend id='b8Cbp'></legend><bdo id='b8Cbp'><pre id='b8Cbp'><center id='b8Cbp'></center></pre></bdo></b><th id='b8Cbp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='b8Cbp'><tfoot id='b8Cbp'></tfoot><dl id='b8Cbp'><fieldset id='b8Cbp'></fieldset></dl></div>
                <tbody id='b8Cbp'></tbody>

                <tfoot id='b8Cbp'></tfoot>
                本文介紹了laravel Eloquent ORM delete() 方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在學習 Laravel.我使用 Eloquent ORM 刪除方法,但得到不同的結果.不是真或假而是空.我設置了一個資源路由,在UsersController中有一個destroy方法.

                Hi I am studying laravel. I use Eloquent ORM delete method but I get a different result.Not true or false but null. I set an resource route and there is a destroy method in UsersController.

                public function destroy($id){
                
                  $res=User::find($id)->delete();
                  if ($res){
                    $data=[
                    'status'=>'1',
                    'msg'=>'success'
                  ];
                  }else{
                    $data=[
                    'status'=>'0',
                    'msg'=>'fail'
                  ];
                  return response()->json($data);
                

                但是我總是得到響應{"status":"0","msg":"failed"},數據庫中的記錄被刪除了.

                But I always get a response {"status":"0","msg":"failed"},the record in the database is deleted.

                然后我使用 dd($res) .它在頁面中顯示為空.

                Then I use dd($res) .It shows null in the page.

                但是從我學習的課程中,它返回一個布爾值 true 或 false.

                But from the course I learn it returns a boolean value true or false.

                我的代碼有錯誤嗎?

                你能告訴我從數據庫中刪除數據時可以得到布爾結果的其他方法嗎?

                Can you tell me some other method that I can get a boolean result when I delete data from database?

                推薦答案

                delete 之前,laravel 有幾個方法.

                Before delete , there are several methods in laravel.

                User::find(1)User::first() 返回一個實例.

                User::find(1) and User::first() return an instance.

                User::where('id',1)->getUser::all() 返回一個實例集合.

                User::where('id',1)->get and User::all() return a collection of instance.

                在模型實例上調用 delete 將返回 true/false

                call delete on an model instance will returns true/false

                $user=User::find(1);
                $user->delete(); //returns true/false
                

                對實例集合調用 delete 將返回一個數字,表示已刪除的記錄數

                call delete on a collection of instance will returns a number which represents the number of the records had been deleted

                //assume you have 10 users, id from 1 to 10;
                $result=User::where('id','<',11)->delete(); //returns 11 (the number of the records had been deleted)
                
                //lets call delete again
                $result2=User::where('id','<',11)->delete(); //returns 0 (we have already delete the id<11 users, so this time we delete nothing, the result should be the number of the records had been deleted(0)  ) 
                

                還有其他刪除方法,你可以調用destroy作為模型靜態方法,如下所示

                Also there are other delete methods, you can call destroy as a model static method like below

                $result=User::destroy(1,2,3);
                $result=User::destroy([1,2,3]);
                $result=User::destroy(collect([1, 2, 3]));
                //these 3 statement do the same thing, delete id =1,2,3 users, returns the number of the records had been deleted
                
                

                還有一點,如果你是 laravel 的新手,你可以使用 php artisan tinker 來查看結果,這樣效率更高,然后 dd($result) , print_r($result);

                One more thing ,if you are new to laravel ,you can use php artisan tinker to see the result, which is more efficient and then dd($result) , print_r($result);

                這篇關于laravel Eloquent ORM delete() 方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                <tfoot id='0S5wF'></tfoot>
                  <tbody id='0S5wF'></tbody>
              1. <small id='0S5wF'></small><noframes id='0S5wF'>

                  <bdo id='0S5wF'></bdo><ul id='0S5wF'></ul>

                    1. <i id='0S5wF'><tr id='0S5wF'><dt id='0S5wF'><q id='0S5wF'><span id='0S5wF'><b id='0S5wF'><form id='0S5wF'><ins id='0S5wF'></ins><ul id='0S5wF'></ul><sub id='0S5wF'></sub></form><legend id='0S5wF'></legend><bdo id='0S5wF'><pre id='0S5wF'><center id='0S5wF'></center></pre></bdo></b><th id='0S5wF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0S5wF'><tfoot id='0S5wF'></tfoot><dl id='0S5wF'><fieldset id='0S5wF'></fieldset></dl></div>

                          <legend id='0S5wF'><style id='0S5wF'><dir id='0S5wF'><q id='0S5wF'></q></dir></style></legend>
                        1. 主站蜘蛛池模板: 日本不卡一区二区三区在线观看 | 伊人亚洲 | 粉色午夜视频 | 国产一级片免费在线观看 | 久久久久国产一级毛片高清网站 | 国产精品久久久久久久免费大片 | a级在线观看 | 一级a爱片久久毛片 | 免费a国产 | 日韩成人在线网址 | 人人爽人人草 | 97精品一区二区 | 视频一区二区中文字幕 | 久久久激情 | 乳色吐息在线观看 | 91久久久www播放日本观看 | 日韩影院一区 | 欧美一区| 欧美影院 | 国产日韩视频在线 | 成人免费在线视频 | 日韩精品免费在线 | yiren22综合网成人 | 久久99久久99精品免视看婷婷 | 国产成人一区二 | 91亚洲国产亚洲国产 | 欧美日韩电影免费观看 | 国产成人久久精品一区二区三区 | 国产精品久久国产精品久久 | 美女逼网站 | 在线观看中文字幕 | 午夜精品久久 | 国产乱码精品一区二区三区忘忧草 | 国产91久久久久蜜臀青青天草二 | 午夜影院视频 | 久热电影 | 日韩成人在线观看 | 久久99成人| 国产精品久久久久av | 亚洲理论在线观看电影 | 美女在线一区二区 |