laravel中数据库的增删改查

    //插入
    public function query1()
    {
//        $bool=DB::table('test')->insert([
//            ['name'=>'james','age'=>'32'],
//            ['name'=>'wade','age'=>'34']
//        ]);
//        var_dump($bool);

    $test = Test::create(
       ['name' => 'antony', 'age'  => '33']
    );
    dd($test);


    }
    //删除
    public function query2()
    {
//        $test = DB::table('test')->where('id','1004')->delete();
//        $test = Test::find(1006)->delete();
        $row = Test::where('name','antony')->delete();
        var_dump($row);
    }
    //修改
    public function query3(){
//        $test = DB::table('test')->where('id','1003')->update(['age'=>'30']);
        $test = Test::where('id','1003')->update(['age'=>'31']);
        var_dump($test);
    }
    //查
    public function query4(){
//        $test = DB::table('test')->get();
//        $test = DB::table('test')->where('id','>','1001')->first();
//        $test = DB::table('test')->where('id','>','1001')->value('name');

//        $test = Test::all();
//        $test = Test::where('id','>','1001')->first();
        $test = Test::where('id','>','1002')->value('name');
        dd($test);
    }

你可能感兴趣的:(laravel中数据库的增删改查)