最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Laravel框架Eloquent ORM刪除數(shù)據(jù)操作示例

 更新時間:2019年12月03日 11:47:43   作者:陳柴Rarin  
這篇文章主要介紹了Laravel框架Eloquent ORM刪除數(shù)據(jù)操作,結(jié)合實例形式分析了laravel框架ORM三種刪除數(shù)據(jù)的方式,需要的朋友可以參考下

本文實例講述了Laravel框架Eloquent ORM刪除數(shù)據(jù)操作。分享給大家供大家參考,具體如下:

這篇文章,以下三個知識點希望大家能夠掌握

如下:

  1. 通過模型刪除
  2. 通過主鍵值刪除
  3. 通過指定條件刪除

NO.1模型刪除

老樣子,我們先新建一個方法,然后輸入代碼。

namespace App\Http\Controllers;
use App\Student;
use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{
    public function orm4()
    {
        $student = Student::find(7);//找到id為7的
        $bool = $student->delete();//刪除
        var_dump($bool);
    }
}

如果他顯示出了一個true,則證明刪除成功,如果沒有刪除成功,則報錯

NO.2通過主鍵值刪除

代碼如下:

namespace App\Http\Controllers;
use App\Student;
use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{
    public function orm4()
    {
        $num = Student::destroy(7);
        var_dump($num);
    }
}

如果他輸出一個數(shù)字1,說明刪除成功,受影響的刪除數(shù)據(jù)總數(shù)為1,當(dāng)然,如果要刪除多條數(shù)據(jù)也很簡單,代碼如下:

namespace App\Http\Controllers;
use App\Student;
use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{
    public function orm2()
    {
        $num = Student::destroy(7,5);
        var_dump($num);
    }
}

效果如下:

這里說明我刪除了兩條數(shù)據(jù)

NO.3通過指定條件刪除

代碼如下:

namespace App\Http\Controllers;
use App\Student;
use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{
    public function orm2()
    {
        $num = Student::where('id','>',3)
        ->delete();
        var_dump($num);
    }
}

這里,id大于三的都會刪除,我就不手動演示了

更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家基于Laravel框架的PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論

沂南县| 三门峡市| 固安县| 唐海县| 华安县| 克山县| 建瓯市| 萝北县| 莎车县| 永吉县| 万宁市| 云龙县| 淮滨县| 佳木斯市| 恭城| 阳原县| 信阳市| 花莲县| 尚义县| 莱西市| 巨野县| 农安县| 江达县| 额尔古纳市| 拉孜县| 屯留县| 旬阳县| 河西区| 庆元县| 湖南省| 揭西县| 桃源县| 潮州市| 万安县| 阜宁县| 道真| 库车县| 长春市| 临颍县| 纳雍县| 陆川县|