操作数据库

//语句传参数
$users = DB::select('select * from hk_admin where id = ?', [$id]);

//处理事务
DB::transaction(function () {
DB::table('hk_admin')->update(['password' => 1]);

//DB::table('hk_admin')->delete();
});

//所有的数据列
$users = DB::table('hk_admin')->get();

//获取一列的值
$users = DB::table('hk_admin')->pluck('real_name');



$users = DB::table('hk_admin')
->whereIn('id', [1, 2, 3])
->get();

$users = DB::table('hk_admin')
->whereColumn([
['real_name', '=', 'last_name'],
['create_time', '>', 'created_at']
])->get();

//添加返回ID
$id = DB::table('users')->insertGetId(
['email' => 'john@example.com', 'real_name' => "zg"]
);

原文地址:https://www.cnblogs.com/zgaspnet/p/8297623.html