2016-05-02 4 views
1

Databetableからデータを削除しようとしています。Laravel 4.2Elequent ORMです。しかし、私は削除することができないよ、ここに私のコードです:Laravel 4.2とElement 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(); ` 

答えて

0

これが正しい使い方ですが、これが唯一の1行を削除します:あなたはあなたが行うことができます複数の行を削除したい場合は

\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(); 
} 
このような何か
+0

ありがとう、それは –

+0

助けてくれてうれしいです。 ) –

関連する問題