如何同时删除两个表数据
public function destroy(Request $request, $id)
{
$order_map = Order_menu_mapping::where('order_id',$id)->get();
$order = Order::find($id);
$order->deleted_by = \Auth::user()->email;
$order->save();
$order_map->save();
if ($order->delete()) {
return ['type' => 'success', 'title' => 'Deleted!', 'message'
=> 'Order has been deleted successfully.'];
}
}
如何同时删除两个表数据
答案 0 :(得分:0)
尝试这种方式
DB::table(DB::raw('FROM orders, order_mappings'))
->join(order_mappings) // wasn't clear how your tables were related
->where('order_id', $_POST['id'])
->delete();