[Laravel-5]-bài 10: Schema Builder cơ bản P3
1. lệnh insert
a. insert 1 bản ghi Route::get('query/insert', function(){
DB::table('product')->insert([
'name'=>'quần đi biển ',
'price'=> 50000,
'cate_id'=>2
]);
return "Insert thành công ";
})
b. insert nhiều bản ghi
Route::get('query/insert-multi', function(){
DB::table('product')->insert(
['name'=>'quần đi biển ','price'=> 50000, 'cate_id'=>2],
['name'=>'quần đi soc ','price'=> 4500, 'cate_id'=>1],
['name'=>'quần dài ','price'=> 5000, 'cate_id'=>3]
);
return "Insert thành công ";
})
2. lệnh update
a. update theo bản ghi .
Route::get('query/update', function(){
DB::table('product')->where('id', 19)->update(['name'=>'quần đi biển ','price'=> 50000]);
return "update ";
})
b. update theo điều kiện
Route::get('query/update', function(){
DB::table('product')->where('id','<', 19)->update(['name'=>'quần đi biển ','price'=> 50000]);
return "update thành công ";
})
3. Lệnh delete
a. lệnh delete theo id,
Route::get('query/delete', function(){
DB::table('product')->where('id', 19)->delete();
return "delete
b. delete theo điều kiện Route::get('query/delete', function(){ DB::table('product')->where('id','>=', 18)->delete();return "delete thành công ";
});
c. delete tất cả bản ghi . Route::get('query/delete', function(){
DB::table('product')->delete();
return "delete thành công ";
});
Không có nhận xét nào:
Đăng nhận xét