我正在尝试使用Laravel 4.2
和Elequent ORM
从//delete incoming calls against this number
\DB::table('incoming_call')
->where("contact_num",'=',$data['mobile'])
->delete();
//delete outgoing calls against this number
\DB::table('outgoing_call')
->where("contact_num",'=',$data['mobile'])
->delete(); `
删除数据。但是我无法删除,这是我的代码:
Public Sub TransferPivotCache(SourcePivot As PivotTable, TargetPivot As PivotTable)
TargetPivot.CacheIndex = SourcePivot.CacheIndex
End Sub
答案 0 :(得分:0)
这是正确的用法,但这只会删除一行:
\DB::table('incoming_call')
->where("contact_num",'=',$data['mobile'])
->first();
->delete();
\DB::table('outgoing_call')
->where("contact_num",'=',$data['mobile'])
->first();
->delete();
如果要删除多行,可以执行以下操作:
$coll = \DB::table('incoming_call')
->where("contact_num",'=',$data['mobile'])
->get();
\DB::table('incoming_call')->destroy($coll->keys());
或者只使用简单的foreach
:
$coll = \DB::table('incoming_call')
->where("contact_num",'=',$data['mobile'])
->get();
foreach($coll as $one){
$one->delete();
}