Blogger Information
Blog 11
fans 1
comment 1
visits 9731
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
2018年5月25日,模型增删改查,闭包,匿名函数的使用
豆芽的博客
Original
823 people have browsed it

//闭包的方式更新

        /医院User::update(['money'=>\think\Db::raw('money-500')],function($query){

            $query->where('age','>',19);

        });

        */

       User::where('age','>',19)

                ->data(['money'=>\think\Db::raw('money+5000')])

                ->update();

        //闭包的方式删除数据

       /*User::destroy(function($query){

            $query->where('age','>',20);

       });

//批量恢复软删除的数据 

       User::update(['delete_time'=>null],function($query){

            $query->where('age','>',20);

       });

       

        */

可以软删除,真实删除传递第二个参数true;

       User::destroy(5);



       //$n = News::get(3);

        // 输出Profile关联模型的email属性

       //echo $n->user->name;


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post