droxlzcgnr639823 2016-05-11 18:07
浏览 46

AngularJS Laravel Pass范围,具有未知数量的变量到数据库

I'm creating an app using Laravel(API) and AngularJS. I have a store and cart using the library ng-cart. Every time I add an item to the cart, it adds to the cart object of an instance. In my database, I have three tables: item,orders,item_order. According to Laravel, I have to use the append command to append multiple items to an order on the item_order table. However, I do not know how many items I will send to the database.

My problem is, how do I pass an unknown number of variables from the scope to the database table item_order? Or more specifically, how to pass those variables from the front-end to API and how to handle that data on the API side?

Any ideas?

  • 写回答

1条回答 默认 最新

  • duanaigua4033 2016-09-20 07:50
    关注

    Simply you can pass them in a json object like this.

    var object = {
        item: $scope.item,
        orders: $scope.orders,
        item_order :$scope.item_order
    }
    

    And you can access this object in you API

    $object = json_decode(file_get_contents("php://input"), true);
    $item = $object['item'];
    $orders = $object['orders'];
    $item_order = $object['orders']
    
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大