如何同时删除order和order_mapping表数据

时间:2019-01-08 07:36:35

标签: laravel laravel-5 laravel-5.4

如何同时删除两个表数据

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.'];
    }
}

如何同时删除两个表数据

1 个答案:

答案 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();