admin 发表于 2023-2-16 18:55:15

laravel 进行删除操作delete 和 destroy方法

<div id="article_content" class="article_content clearfix">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
                <div id="content_views" class="htmledit_views">
                  <p>student::where('age' >'3')->delete();</p>
<p>用delete的删除操作</p>
<p>$a &#61; 3;</p>
<p>student::destroy($a);</p>
<p>用destroy直接删除索引等于3的记录</p>
<p>2.使用软删除的方法去删除数据记录</p>
<p>首先引用软删除&#xff08;模型里面可以引用&#xff09;</p>
<p>use SoftDeletes&#xff1b;</p>
<p>protected $dates &#61; ['字段名']&#xff1b;</p>
<p>调用软删除&#xff0c;</p>
<p>先查找 student::find(5);</p>
<p>使用删除</p>
<p>student::destroy(5);</p>
<p>执行删除成功&#xff0c;会在字段名里面出现一个时间撮代表数据删除成功</p>
<p></p>
<p></p>
<p>如何查询软删除的数据</p>
<p>可以使用withTrashed方法</p>
<p></p>
<p>只取出全部软删除的数据</p>
<p>onlyTrashed方法</p>
<p></p>
<p>  恢复软删除数据</p>
<p></p>
<p> </p>
<p> </p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
                </div>
      </div>
      <div id="treeSkill"></div>
页: [1]
查看完整版本: laravel 进行删除操作delete 和 destroy方法