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

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

        <legend id='OnNxm'><style id='OnNxm'><dir id='OnNxm'><q id='OnNxm'></q></dir></style></legend>
        <tfoot id='OnNxm'></tfoot>
          <bdo id='OnNxm'></bdo><ul id='OnNxm'></ul>
      1. Laravel 中的 destroy() 和 delete() 方法有什么区别?

        时间:2023-09-23

            • <i id='72yFX'><tr id='72yFX'><dt id='72yFX'><q id='72yFX'><span id='72yFX'><b id='72yFX'><form id='72yFX'><ins id='72yFX'></ins><ul id='72yFX'></ul><sub id='72yFX'></sub></form><legend id='72yFX'></legend><bdo id='72yFX'><pre id='72yFX'><center id='72yFX'></center></pre></bdo></b><th id='72yFX'></th></span></q></dt></tr></i><div id='72yFX'><tfoot id='72yFX'></tfoot><dl id='72yFX'><fieldset id='72yFX'></fieldset></dl></div>
              <legend id='72yFX'><style id='72yFX'><dir id='72yFX'><q id='72yFX'></q></dir></style></legend>
            • <tfoot id='72yFX'></tfoot>
                <tbody id='72yFX'></tbody>

                <small id='72yFX'></small><noframes id='72yFX'>

                  <bdo id='72yFX'></bdo><ul id='72yFX'></ul>
                • 本文介绍了Laravel 中的 destroy() 和 delete() 方法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在使用 Laravel 4 时遇到了一个小问题.我想对记录使用 delete() 方法,但由于某种原因它实际上并没有删除记录.destroy() 确实如此,所以我的代码很好.另外,如果我将 Teetime::where('date', '=', $formattedDate)->count() 传递给我的视图,我会得到一个正确的.有什么问题?

                  I'm having a minor issue with Laravel 4. I'd like to use the delete() method on a record but for some reason it doesn't actually delete the record. destroy() does, though, so my code is good. Also, if I pass Teetime::where('date', '=', $formattedDate)->count() to my view I get one which is correct. What's the problem?

                          if($action=="delete") {
                              $teetime = Teetime::where('date', '=', $formattedDate)->firstOrFail();
                              // for some reason $teetime->delete() doesn't work
                              Teetime::destroy($teetime->id);
                          }
                  

                  推荐答案

                  • destroy 是直接(通过对象或模型)删除实体的正确方法.
                    • destroy is correct method for removing an entity directly (via object or model).
                    • 示例:

                      $teetime = Teetime::where('date', '=', $formattedDate)->firstOrFail();
                      $teetime->destroy();
                      

                      • delete 只能在查询构建器中调用
                        • delete can only be called in query builder
                        • 示例:

                          $teetime = Teetime::where('date', '=', $formattedDate)->delete();
                          

                          来自文档:

                          User::destroy(1);
                          
                          User::destroy(array(1, 2, 3));
                          
                          User::destroy(1, 2, 3);
                          

                          当然,您也可以对一组模型运行删除查询:

                          Of course, you may also run a delete query on a set of models:

                          $affectedRows = User::where('votes', '>', 100)->delete();
                          

                          更多信息:http://laravel.com/docs/eloquent

                          这篇关于Laravel 中的 destroy() 和 delete() 方法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:laravel Eloquent ORM delete() 方法 下一篇:如何更新 Laravel Eloquent 管理的时间戳(created_at 和

                  相关文章

                  最新文章

                      <tfoot id='GFpvS'></tfoot>
                      <legend id='GFpvS'><style id='GFpvS'><dir id='GFpvS'><q id='GFpvS'></q></dir></style></legend>
                      • <bdo id='GFpvS'></bdo><ul id='GFpvS'></ul>
                      <i id='GFpvS'><tr id='GFpvS'><dt id='GFpvS'><q id='GFpvS'><span id='GFpvS'><b id='GFpvS'><form id='GFpvS'><ins id='GFpvS'></ins><ul id='GFpvS'></ul><sub id='GFpvS'></sub></form><legend id='GFpvS'></legend><bdo id='GFpvS'><pre id='GFpvS'><center id='GFpvS'></center></pre></bdo></b><th id='GFpvS'></th></span></q></dt></tr></i><div id='GFpvS'><tfoot id='GFpvS'></tfoot><dl id='GFpvS'><fieldset id='GFpvS'></fieldset></dl></div>

                    1. <small id='GFpvS'></small><noframes id='GFpvS'>