pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <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="8wx33nm" 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="o3jix3e" 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() 方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在學(xué)習(xí) Laravel.我使用 Eloquent ORM 刪除方法,但得到不同的結(jié)果.不是真或假而是空.我設(shè)置了一個資源路由,在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);
                

                但是我總是得到響應(yīng){"status":"0","msg":"failed"},數(shù)據(jù)庫中的記錄被刪除了.

                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.

                但是從我學(xué)習(xí)的課程中,它返回一個布爾值 true 或 false.

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

                我的代碼有錯誤嗎?

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

                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.

                在模型實例上調(diào)用 delete 將返回 true/false

                call delete on an model instance will returns true/false

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

                對實例集合調(diào)用 delete 將返回一個數(shù)字,表示已刪除的記錄數(shù)

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

                還有其他刪除方法,你可以調(diào)用destroy作為模型靜態(tài)方法,如下所示

                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 來查看結(jié)果,這樣效率更高,然后 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);

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

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

                相關(guān)文檔推薦

                MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語句amp;foreach 循環(huán))
                Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務(wù)器還是從同一用戶獲取記錄?)
                PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數(shù))
                Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問被拒絕)
                <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="iqcg8sy" 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. 主站蜘蛛池模板: 对辊破碎机-液压双辊式,强力双齿辊,四辊破碎机价格_巩义市金联机械设备生产厂家 | 10吨无线拉力计-2吨拉力计价格-上海佳宜电子科技有限公司 | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 山楂片_雪花_迷你山楂片_山楂条饼厂家-青州市丰源食品厂 | 低噪声电流前置放大器-SR570电流前置放大器-深圳市嘉士达精密仪器有限公司 | SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 酵素生产厂家_酵素OEM_酵素加盟_酵素ODM_酵素原料厂家_厦门益力康 | 电子天平-华志电子天平厂家 | 重庆中专|职高|技校招生-重庆中专招生网 | PCB接线端子_栅板式端子_线路板连接器_端子排生产厂家-置恒电气 喷码机,激光喷码打码机,鸡蛋打码机,手持打码机,自动喷码机,一物一码防伪溯源-恒欣瑞达有限公司 假肢-假肢价格-假肢厂家-河南假肢-郑州市力康假肢矫形器有限公司 | 底部填充胶_电子封装胶_芯片封装胶_芯片底部填充胶厂家-东莞汉思新材料 | 美的商用净水器_美的直饮机_一级代理经销商_Midea租赁价格-厂家反渗透滤芯-直饮水批发品牌售后 | 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂_帽子厂_浙江高普制帽厂 | 蜂蜜瓶-玻璃瓶-玻璃瓶厂-玻璃瓶生产厂家-徐州贵邦玻璃制品有限公司 | 医养体检包_公卫随访箱_慢病随访包_家签随访包_随访一体机-济南易享医疗科技有限公司 | 股指期货-期货开户-交易手续费佣金加1分-保证金低-期货公司排名靠前-万利信息开户 | 英超直播_英超免费在线高清直播_英超视频在线观看无插件-24直播网 | 济宁工业提升门|济宁电动防火门|济宁快速堆积门-济宁市统一电动门有限公司 | 空心明胶胶囊|植物胶囊|清真胶囊|浙江绿键胶囊有限公司欢迎您! | 小型手持气象站-空气负氧离子监测站-多要素微气象传感器-山东天合环境科技有限公司 | ERP企业管理系统永久免费版_在线ERP系统_OA办公_云版软件官网 | 光纤测温-荧光光纤测温系统-福州华光天锐光电科技有限公司 | 成都竞价托管_抖音代运营_网站建设_成都SEM外包-成都智网创联网络科技有限公司 | 扒渣机厂家_扒渣机价格_矿用扒渣机_铣挖机_撬毛台车_襄阳永力通扒渣机公司 | 宁波普瑞思邻苯二甲酸盐检测仪,ROHS2.0检测设备,ROHS2.0测试仪厂家 | 3dmax渲染-效果图渲染-影视动画渲染-北京快渲科技有限公司 | 数码听觉统合训练系统-儿童感觉-早期言语评估与训练系统-北京鑫泰盛世科技发展有限公司 | 盘古网络技术有限公司| 一体化隔油提升设备-餐饮油水分离器-餐厨垃圾处理设备-隔油池-盐城金球环保产业发展有限公司 | 杭州顺源过滤机械有限公司官网-压滤机_板框压滤机_厢式隔膜压滤机厂家 | 深圳希玛林顺潮眼科医院(官网)│深圳眼科医院│医保定点│香港希玛林顺潮眼科中心连锁品牌 | 电竞学校_电子竞技培训学校学院-梦竞未来电竞学校官网 | 美国HASKEL增压泵-伊莱科elettrotec流量开关-上海方未机械设备有限公司 | 超声波流量计_流量标准装置生产厂家 _河南盛天精密测控 | LED投光灯-工矿灯-led路灯头-工业灯具 - 山东普瑞斯照明科技有限公司 | 北京工业设计公司-产品外观设计-产品设计公司-千策良品工业设计 北京翻译公司-专业合同翻译-医学标书翻译收费标准-慕迪灵 | 北京银联移动POS机办理_收银POS机_智能pos机_刷卡机_收银系统_个人POS机-谷骐科技【官网】 | 耐高温电缆厂家-远洋高温电缆| 定坤静电科技静电消除器厂家-除静电设备 | 自清洗过滤器_全自动过滤器_全自动反冲洗过滤器_量子过滤器-滑漮滴 | 商标转让-商标注册-商标查询-软著专利服务平台 - 赣江万网 |