How to pass array data from vuejs to laravel api controllerUpdate multiple data using same variable name input from a form into single column in database in LaravelLaravel API - Pulling large amounts of data (json)Passing data from a textarea to a function and routingHow to pass javascript variable from laravel controller to vuejs componentLaravel VueJs Array'sHow to pass Laravel Resource API data to Vuejs?Search in vuejs with laravel backend apiLaravel many to many with input pivot tableVuejs and Laravel: How to use http get to pass an array to Laravel controllerHow to pic data from cart into form using v-form by api?

Switch "when" cannot see constants?

SQL counting distinct over partition

Is using haveibeenpwned to validate password strength rational?

How come the nude protesters were not arrested?

Overlapping String-Blocks

Winning Strategy for the Magician and his Apprentice

Why are trash cans referred to as "zafacón" in Puerto Rico?

Did Milano or Benatar approve or comment on their namesake MCU ships?

Why do some employees fill out a W-4 and some don't?

Longest bridge/tunnel that can be cycled over/through?

Geopandas and QGIS Calulating Different Polygon Area Values?

1980s live-action movie where individually-coloured nations on clouds fight

A IP can traceroute to it, but can not ping

Should I give professor gift at the beginning of my PhD?

Is separation provided in class F airspace?

Is it possible to have the age of the universe be unknown?

Wooden cooking layout

How do governments keep track of their issued currency?

Meaning of 'lose their grip on the groins of their followers'

How to hide rifle during medieval town entrance inspection?

Why can my keyboard only digest 6 keypresses at a time?

How can I make some of my chapters "come to life"?

Is a lack of character descriptions a problem?

How to hide an urban landmark?



How to pass array data from vuejs to laravel api controller


Update multiple data using same variable name input from a form into single column in database in LaravelLaravel API - Pulling large amounts of data (json)Passing data from a textarea to a function and routingHow to pass javascript variable from laravel controller to vuejs componentLaravel VueJs Array'sHow to pass Laravel Resource API data to Vuejs?Search in vuejs with laravel backend apiLaravel many to many with input pivot tableVuejs and Laravel: How to use http get to pass an array to Laravel controllerHow to pic data from cart into form using v-form by api?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I want to make an invoice system with laravel using vuejs by api. Firstly show all product and when i click add to cart it added.



Here is the screenshot:View Screenshot



Now i want to send input fill data to order_masters table and including last inserted ID cart data send order_details table.



but i cant not pass the whole data. sometime pass customer information but not cart data.



N. B: I am using vuejs, vform and API



My component code is given below:



<template>
<div class="row">
<div class="col-md-7">
<div class="col-md-11">
<input type="hidden" v-model="field">
<input type="search" v-model="query" class="form-control form-control-sm mb-3" placeholder="Search Here">
</div>
<div class="row justify-content-center">
<div v-show="products.length" v-for="(product, id) in products" :key="id" class="card col-xl-3 col-md-3 col-sm-3 mb-5 mr-5 float-left" style="background-color:lightgray">
<div class="card-body">
<h5 class="card-title">product.name</h5>
<p class="card-text"><input type="text" v-model="product.qty" class="form-control form-control-sm mb-2"></p>
<strong class="">
product.price TK
</strong>
<button class="btn btn-sm btn-primary float-right" @click="addToCart(product)">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
</div>
<div v-show="!products.length" class="alert alert-danger text-center" role="alert">
<strong>Opps! No Data Found!</strong>
</div>
<pagination v-if="pagination.last_page > 1" :pagination="pagination" :offset="5" @paginate="query === ''? showProduct(): searchProduct()"></pagination>
</div>

<div class="col-md-5 float-righ">
<form @submit.prevent="store" @keydown="form.onKeydown($event)">
<alert-error :form="form"></alert-error>
<div class="row mb-2">
<label for="" class="col-md-3 font-weight-bold">Name</label>
<div class="col-md-9">
<input type="text" v-model="form.name" name="name" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('name') ">
<has-error :form="form" field="name"></has-error>
</div>
</div>
<div class="row mb-2">
<label for="" class="col-md-3 font-weight-bold">Phone</label>
<div class="col-md-9">
<input type="text" v-model="form.phone" name="phone" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('phone') ">
<has-error :form="form" field="phone"></has-error>
</div>
</div>
<div class="row mb-2">
<label for="" class="col-md-3 font-weight-bold">Address</label>
<div class="col-md-9">
<input type="text" v-model="form.address" name="address" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('address') " >
<has-error :form="form" field="address"></has-error>
</div>
</div>
<div class="mb-5">
<input type="button" class="btn btn-sm btn-danger float-left" @click="clearCart" value="Clear" />
<button type="submit" :disabled="form.busy" class="btn btn-sm btn-success float-right" @click="store">Checkout</button>
</div>
<table class="table table-sm table-bordered table-striped">
<thead class="text-center">
<tr>
<th>ID</th>
<th>Name</th>
<th>Qty</th>
<th>Price</th>
<th>L/T</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr v-for="(cart, i) in carts" :key="i">
<td class="text-center"><input type="hidden" name="pro_id[]" v-model="form.pro_id"> cart.id</td>
<td>cart.name </td>
<td class="text-right" name="qty"><input type="hidden" name="qty[]" v-model="form.qty">cart.qty</td>
<td class="text-right" name="unit_price"><input type="hidden" name="pro_id[]" v-model="form.price">cart.price</td>
<td class="text-right">cart.price*cart.qty</td>
<td class="text-center"><button type="button" @click="removeProduct(i)" class="btn btn-sm btn-danger">x</button></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4" class="text-right font-weight-bold">Total =</td>
<td class="text-right"> total/-</td>
</tr>
</tfoot>
</table>

</form>
</div>
<vue-progress-bar></vue-progress-bar>
<vue-snotify></vue-snotify>
</div>




<script>
export default
data()
return
field: 'name',
query: '',
form: new Form(
'name': '',
'phone': '',
'address':'',
'pro_id' : [],
'qty' : [],
'unit_price' : []
),
products:[],
carts:[],
pagination:
current_page: 1


,
methods:
store()
var data =
carts: this.carts,

this.$Progress.start()
this.form.busy = true
this.form.post('api/pos', data)
.then( res =>
this.form.reset()
this.form.clear()
this.$Progress.finish()
console.log(data)
)
.catch( e =>
this.$Progress.fail()
console.log(e)
)




</script>


Here is API Controller Function:



public function store(Request $request)

$carts = json_decode($request->getContent('data'), true);

$this->validate($request,[
'name' => 'required',
'phone' => 'required',
'address' => 'required'
]);

$order = new OrderMaster;
$order->name = $request->name;
$order->phone = $request->phone;
$order->address = $request->address;
$order->save();

$order_id = DB::getPdo()->lastInsertId();

foreach ($carts as $cart)

OrderDetails::create([
'order_id' => $order_id,
'product_id' => ?,
'qty' => ?,
'unite_price' => ?,
]);











share|improve this question




























    1















    I want to make an invoice system with laravel using vuejs by api. Firstly show all product and when i click add to cart it added.



    Here is the screenshot:View Screenshot



    Now i want to send input fill data to order_masters table and including last inserted ID cart data send order_details table.



    but i cant not pass the whole data. sometime pass customer information but not cart data.



    N. B: I am using vuejs, vform and API



    My component code is given below:



    <template>
    <div class="row">
    <div class="col-md-7">
    <div class="col-md-11">
    <input type="hidden" v-model="field">
    <input type="search" v-model="query" class="form-control form-control-sm mb-3" placeholder="Search Here">
    </div>
    <div class="row justify-content-center">
    <div v-show="products.length" v-for="(product, id) in products" :key="id" class="card col-xl-3 col-md-3 col-sm-3 mb-5 mr-5 float-left" style="background-color:lightgray">
    <div class="card-body">
    <h5 class="card-title">product.name</h5>
    <p class="card-text"><input type="text" v-model="product.qty" class="form-control form-control-sm mb-2"></p>
    <strong class="">
    product.price TK
    </strong>
    <button class="btn btn-sm btn-primary float-right" @click="addToCart(product)">
    <i class="fas fa-plus"></i>
    </button>
    </div>
    </div>
    </div>
    <div v-show="!products.length" class="alert alert-danger text-center" role="alert">
    <strong>Opps! No Data Found!</strong>
    </div>
    <pagination v-if="pagination.last_page > 1" :pagination="pagination" :offset="5" @paginate="query === ''? showProduct(): searchProduct()"></pagination>
    </div>

    <div class="col-md-5 float-righ">
    <form @submit.prevent="store" @keydown="form.onKeydown($event)">
    <alert-error :form="form"></alert-error>
    <div class="row mb-2">
    <label for="" class="col-md-3 font-weight-bold">Name</label>
    <div class="col-md-9">
    <input type="text" v-model="form.name" name="name" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('name') ">
    <has-error :form="form" field="name"></has-error>
    </div>
    </div>
    <div class="row mb-2">
    <label for="" class="col-md-3 font-weight-bold">Phone</label>
    <div class="col-md-9">
    <input type="text" v-model="form.phone" name="phone" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('phone') ">
    <has-error :form="form" field="phone"></has-error>
    </div>
    </div>
    <div class="row mb-2">
    <label for="" class="col-md-3 font-weight-bold">Address</label>
    <div class="col-md-9">
    <input type="text" v-model="form.address" name="address" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('address') " >
    <has-error :form="form" field="address"></has-error>
    </div>
    </div>
    <div class="mb-5">
    <input type="button" class="btn btn-sm btn-danger float-left" @click="clearCart" value="Clear" />
    <button type="submit" :disabled="form.busy" class="btn btn-sm btn-success float-right" @click="store">Checkout</button>
    </div>
    <table class="table table-sm table-bordered table-striped">
    <thead class="text-center">
    <tr>
    <th>ID</th>
    <th>Name</th>
    <th>Qty</th>
    <th>Price</th>
    <th>L/T</th>
    <th>Action</th>
    </tr>
    </thead>
    <tbody>
    <tr v-for="(cart, i) in carts" :key="i">
    <td class="text-center"><input type="hidden" name="pro_id[]" v-model="form.pro_id"> cart.id</td>
    <td>cart.name </td>
    <td class="text-right" name="qty"><input type="hidden" name="qty[]" v-model="form.qty">cart.qty</td>
    <td class="text-right" name="unit_price"><input type="hidden" name="pro_id[]" v-model="form.price">cart.price</td>
    <td class="text-right">cart.price*cart.qty</td>
    <td class="text-center"><button type="button" @click="removeProduct(i)" class="btn btn-sm btn-danger">x</button></td>
    </tr>
    </tbody>
    <tfoot>
    <tr>
    <td colspan="4" class="text-right font-weight-bold">Total =</td>
    <td class="text-right"> total/-</td>
    </tr>
    </tfoot>
    </table>

    </form>
    </div>
    <vue-progress-bar></vue-progress-bar>
    <vue-snotify></vue-snotify>
    </div>




    <script>
    export default
    data()
    return
    field: 'name',
    query: '',
    form: new Form(
    'name': '',
    'phone': '',
    'address':'',
    'pro_id' : [],
    'qty' : [],
    'unit_price' : []
    ),
    products:[],
    carts:[],
    pagination:
    current_page: 1


    ,
    methods:
    store()
    var data =
    carts: this.carts,

    this.$Progress.start()
    this.form.busy = true
    this.form.post('api/pos', data)
    .then( res =>
    this.form.reset()
    this.form.clear()
    this.$Progress.finish()
    console.log(data)
    )
    .catch( e =>
    this.$Progress.fail()
    console.log(e)
    )




    </script>


    Here is API Controller Function:



    public function store(Request $request)

    $carts = json_decode($request->getContent('data'), true);

    $this->validate($request,[
    'name' => 'required',
    'phone' => 'required',
    'address' => 'required'
    ]);

    $order = new OrderMaster;
    $order->name = $request->name;
    $order->phone = $request->phone;
    $order->address = $request->address;
    $order->save();

    $order_id = DB::getPdo()->lastInsertId();

    foreach ($carts as $cart)

    OrderDetails::create([
    'order_id' => $order_id,
    'product_id' => ?,
    'qty' => ?,
    'unite_price' => ?,
    ]);











    share|improve this question
























      1












      1








      1


      1






      I want to make an invoice system with laravel using vuejs by api. Firstly show all product and when i click add to cart it added.



      Here is the screenshot:View Screenshot



      Now i want to send input fill data to order_masters table and including last inserted ID cart data send order_details table.



      but i cant not pass the whole data. sometime pass customer information but not cart data.



      N. B: I am using vuejs, vform and API



      My component code is given below:



      <template>
      <div class="row">
      <div class="col-md-7">
      <div class="col-md-11">
      <input type="hidden" v-model="field">
      <input type="search" v-model="query" class="form-control form-control-sm mb-3" placeholder="Search Here">
      </div>
      <div class="row justify-content-center">
      <div v-show="products.length" v-for="(product, id) in products" :key="id" class="card col-xl-3 col-md-3 col-sm-3 mb-5 mr-5 float-left" style="background-color:lightgray">
      <div class="card-body">
      <h5 class="card-title">product.name</h5>
      <p class="card-text"><input type="text" v-model="product.qty" class="form-control form-control-sm mb-2"></p>
      <strong class="">
      product.price TK
      </strong>
      <button class="btn btn-sm btn-primary float-right" @click="addToCart(product)">
      <i class="fas fa-plus"></i>
      </button>
      </div>
      </div>
      </div>
      <div v-show="!products.length" class="alert alert-danger text-center" role="alert">
      <strong>Opps! No Data Found!</strong>
      </div>
      <pagination v-if="pagination.last_page > 1" :pagination="pagination" :offset="5" @paginate="query === ''? showProduct(): searchProduct()"></pagination>
      </div>

      <div class="col-md-5 float-righ">
      <form @submit.prevent="store" @keydown="form.onKeydown($event)">
      <alert-error :form="form"></alert-error>
      <div class="row mb-2">
      <label for="" class="col-md-3 font-weight-bold">Name</label>
      <div class="col-md-9">
      <input type="text" v-model="form.name" name="name" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('name') ">
      <has-error :form="form" field="name"></has-error>
      </div>
      </div>
      <div class="row mb-2">
      <label for="" class="col-md-3 font-weight-bold">Phone</label>
      <div class="col-md-9">
      <input type="text" v-model="form.phone" name="phone" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('phone') ">
      <has-error :form="form" field="phone"></has-error>
      </div>
      </div>
      <div class="row mb-2">
      <label for="" class="col-md-3 font-weight-bold">Address</label>
      <div class="col-md-9">
      <input type="text" v-model="form.address" name="address" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('address') " >
      <has-error :form="form" field="address"></has-error>
      </div>
      </div>
      <div class="mb-5">
      <input type="button" class="btn btn-sm btn-danger float-left" @click="clearCart" value="Clear" />
      <button type="submit" :disabled="form.busy" class="btn btn-sm btn-success float-right" @click="store">Checkout</button>
      </div>
      <table class="table table-sm table-bordered table-striped">
      <thead class="text-center">
      <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Qty</th>
      <th>Price</th>
      <th>L/T</th>
      <th>Action</th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="(cart, i) in carts" :key="i">
      <td class="text-center"><input type="hidden" name="pro_id[]" v-model="form.pro_id"> cart.id</td>
      <td>cart.name </td>
      <td class="text-right" name="qty"><input type="hidden" name="qty[]" v-model="form.qty">cart.qty</td>
      <td class="text-right" name="unit_price"><input type="hidden" name="pro_id[]" v-model="form.price">cart.price</td>
      <td class="text-right">cart.price*cart.qty</td>
      <td class="text-center"><button type="button" @click="removeProduct(i)" class="btn btn-sm btn-danger">x</button></td>
      </tr>
      </tbody>
      <tfoot>
      <tr>
      <td colspan="4" class="text-right font-weight-bold">Total =</td>
      <td class="text-right"> total/-</td>
      </tr>
      </tfoot>
      </table>

      </form>
      </div>
      <vue-progress-bar></vue-progress-bar>
      <vue-snotify></vue-snotify>
      </div>




      <script>
      export default
      data()
      return
      field: 'name',
      query: '',
      form: new Form(
      'name': '',
      'phone': '',
      'address':'',
      'pro_id' : [],
      'qty' : [],
      'unit_price' : []
      ),
      products:[],
      carts:[],
      pagination:
      current_page: 1


      ,
      methods:
      store()
      var data =
      carts: this.carts,

      this.$Progress.start()
      this.form.busy = true
      this.form.post('api/pos', data)
      .then( res =>
      this.form.reset()
      this.form.clear()
      this.$Progress.finish()
      console.log(data)
      )
      .catch( e =>
      this.$Progress.fail()
      console.log(e)
      )




      </script>


      Here is API Controller Function:



      public function store(Request $request)

      $carts = json_decode($request->getContent('data'), true);

      $this->validate($request,[
      'name' => 'required',
      'phone' => 'required',
      'address' => 'required'
      ]);

      $order = new OrderMaster;
      $order->name = $request->name;
      $order->phone = $request->phone;
      $order->address = $request->address;
      $order->save();

      $order_id = DB::getPdo()->lastInsertId();

      foreach ($carts as $cart)

      OrderDetails::create([
      'order_id' => $order_id,
      'product_id' => ?,
      'qty' => ?,
      'unite_price' => ?,
      ]);











      share|improve this question














      I want to make an invoice system with laravel using vuejs by api. Firstly show all product and when i click add to cart it added.



      Here is the screenshot:View Screenshot



      Now i want to send input fill data to order_masters table and including last inserted ID cart data send order_details table.



      but i cant not pass the whole data. sometime pass customer information but not cart data.



      N. B: I am using vuejs, vform and API



      My component code is given below:



      <template>
      <div class="row">
      <div class="col-md-7">
      <div class="col-md-11">
      <input type="hidden" v-model="field">
      <input type="search" v-model="query" class="form-control form-control-sm mb-3" placeholder="Search Here">
      </div>
      <div class="row justify-content-center">
      <div v-show="products.length" v-for="(product, id) in products" :key="id" class="card col-xl-3 col-md-3 col-sm-3 mb-5 mr-5 float-left" style="background-color:lightgray">
      <div class="card-body">
      <h5 class="card-title">product.name</h5>
      <p class="card-text"><input type="text" v-model="product.qty" class="form-control form-control-sm mb-2"></p>
      <strong class="">
      product.price TK
      </strong>
      <button class="btn btn-sm btn-primary float-right" @click="addToCart(product)">
      <i class="fas fa-plus"></i>
      </button>
      </div>
      </div>
      </div>
      <div v-show="!products.length" class="alert alert-danger text-center" role="alert">
      <strong>Opps! No Data Found!</strong>
      </div>
      <pagination v-if="pagination.last_page > 1" :pagination="pagination" :offset="5" @paginate="query === ''? showProduct(): searchProduct()"></pagination>
      </div>

      <div class="col-md-5 float-righ">
      <form @submit.prevent="store" @keydown="form.onKeydown($event)">
      <alert-error :form="form"></alert-error>
      <div class="row mb-2">
      <label for="" class="col-md-3 font-weight-bold">Name</label>
      <div class="col-md-9">
      <input type="text" v-model="form.name" name="name" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('name') ">
      <has-error :form="form" field="name"></has-error>
      </div>
      </div>
      <div class="row mb-2">
      <label for="" class="col-md-3 font-weight-bold">Phone</label>
      <div class="col-md-9">
      <input type="text" v-model="form.phone" name="phone" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('phone') ">
      <has-error :form="form" field="phone"></has-error>
      </div>
      </div>
      <div class="row mb-2">
      <label for="" class="col-md-3 font-weight-bold">Address</label>
      <div class="col-md-9">
      <input type="text" v-model="form.address" name="address" class="form-control form-control-sm" :class=" 'is-invalid': form.errors.has('address') " >
      <has-error :form="form" field="address"></has-error>
      </div>
      </div>
      <div class="mb-5">
      <input type="button" class="btn btn-sm btn-danger float-left" @click="clearCart" value="Clear" />
      <button type="submit" :disabled="form.busy" class="btn btn-sm btn-success float-right" @click="store">Checkout</button>
      </div>
      <table class="table table-sm table-bordered table-striped">
      <thead class="text-center">
      <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Qty</th>
      <th>Price</th>
      <th>L/T</th>
      <th>Action</th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="(cart, i) in carts" :key="i">
      <td class="text-center"><input type="hidden" name="pro_id[]" v-model="form.pro_id"> cart.id</td>
      <td>cart.name </td>
      <td class="text-right" name="qty"><input type="hidden" name="qty[]" v-model="form.qty">cart.qty</td>
      <td class="text-right" name="unit_price"><input type="hidden" name="pro_id[]" v-model="form.price">cart.price</td>
      <td class="text-right">cart.price*cart.qty</td>
      <td class="text-center"><button type="button" @click="removeProduct(i)" class="btn btn-sm btn-danger">x</button></td>
      </tr>
      </tbody>
      <tfoot>
      <tr>
      <td colspan="4" class="text-right font-weight-bold">Total =</td>
      <td class="text-right"> total/-</td>
      </tr>
      </tfoot>
      </table>

      </form>
      </div>
      <vue-progress-bar></vue-progress-bar>
      <vue-snotify></vue-snotify>
      </div>




      <script>
      export default
      data()
      return
      field: 'name',
      query: '',
      form: new Form(
      'name': '',
      'phone': '',
      'address':'',
      'pro_id' : [],
      'qty' : [],
      'unit_price' : []
      ),
      products:[],
      carts:[],
      pagination:
      current_page: 1


      ,
      methods:
      store()
      var data =
      carts: this.carts,

      this.$Progress.start()
      this.form.busy = true
      this.form.post('api/pos', data)
      .then( res =>
      this.form.reset()
      this.form.clear()
      this.$Progress.finish()
      console.log(data)
      )
      .catch( e =>
      this.$Progress.fail()
      console.log(e)
      )




      </script>


      Here is API Controller Function:



      public function store(Request $request)

      $carts = json_decode($request->getContent('data'), true);

      $this->validate($request,[
      'name' => 'required',
      'phone' => 'required',
      'address' => 'required'
      ]);

      $order = new OrderMaster;
      $order->name = $request->name;
      $order->phone = $request->phone;
      $order->address = $request->address;
      $order->save();

      $order_id = DB::getPdo()->lastInsertId();

      foreach ($carts as $cart)

      OrderDetails::create([
      'order_id' => $order_id,
      'product_id' => ?,
      'qty' => ?,
      'unite_price' => ?,
      ]);








      laravel api vue.js cart shopping-cart






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 17:53









      Mizanur RahmanMizanur Rahman

      276




      276






















          2 Answers
          2






          active

          oldest

          votes


















          0














          First, you're calling form.post wrong. Second parameter is not additional data, but config options for axios.request call.



          In order to send carts array you should add it to the form itself:



          form: new Form(
          'name': '',
          'phone': '',
          'address':'',
          'pro_id' : [],
          'qty' : [],
          'unit_price' : [],
          'carts' : [], // <-- added
          ),


          Then, replace usage of carts with form.carts in your template (and methods).



          Now, carts will be sent to the server along with other data.



          And lastly, you don't need to use json_decode at all.



          //...
          $data = $this->validate($request, [
          'name' => 'required',
          'phone' => 'required',
          'address' => 'required',
          'carts' => 'required|array',
          'carts.*.name' => 'string',
          'carts.*.id' => 'integer',
          'carts.*.qty' => 'integer',
          'carts.*.price' => 'numeric',
          ]);


          Then, you can use $data as a source of data.



          foreach ($data['carts'] as $cart) 
          OrderDetails::create([
          'order_id' => $order_id,
          'product_id' => $cart['id'],
          'qty' => $cart['qty'],
          'unite_price' => $cart['price'],
          ]);






          share|improve this answer























          • unfortunately it doesn't work.

            – Mizanur Rahman
            Mar 26 at 8:53











          • @MizanurRahman It should work. Perhaps you'd share more information?

            – Styx
            Mar 26 at 8:54


















          0














          I had been done it in other way. Not using vform i used axios. but i want to done it using vform.



          return
          field: 'name',
          query: '',
          form:
          'name': '',
          'phone': '',
          'address':''
          ,
          products:[],
          carts:[],
          pagination:
          current_page: 1


          store()
          let client =
          cli: this.form

          let data =
          carts: this.carts


          this.$Progress.start()
          axios.post('api/pos', data, client)
          .then( res =>
          this.$Progress.finish()
          console.log(res)
          )
          .catch( e =>
          this.$Progress.fail()
          console.log(e)
          )




          Controller:



          $carts = json_decode($request->getContent('client','data'), true);

          $customer = $carts['client'];
          $pro_info = $carts['data'];

          foreach ($customer as $cus)
          $order = new OrderMaster;
          $order->name = $cus['name'];
          $order->phone = $cus['phone'];
          $order->address = $cus['address'];
          $order->save();



          $order_id = DB::getPdo()->lastInsertId();

          foreach ($pro_info as $cart)
          foreach ($cart as $c)
          OrderDetails::create([
          'order_id' => $order_id,
          'product_id' => $c['id'],
          'qty' => $c['qty'],
          'unit_price' => $c['price'],
          ]);







          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326767%2fhow-to-pass-array-data-from-vuejs-to-laravel-api-controller%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            First, you're calling form.post wrong. Second parameter is not additional data, but config options for axios.request call.



            In order to send carts array you should add it to the form itself:



            form: new Form(
            'name': '',
            'phone': '',
            'address':'',
            'pro_id' : [],
            'qty' : [],
            'unit_price' : [],
            'carts' : [], // <-- added
            ),


            Then, replace usage of carts with form.carts in your template (and methods).



            Now, carts will be sent to the server along with other data.



            And lastly, you don't need to use json_decode at all.



            //...
            $data = $this->validate($request, [
            'name' => 'required',
            'phone' => 'required',
            'address' => 'required',
            'carts' => 'required|array',
            'carts.*.name' => 'string',
            'carts.*.id' => 'integer',
            'carts.*.qty' => 'integer',
            'carts.*.price' => 'numeric',
            ]);


            Then, you can use $data as a source of data.



            foreach ($data['carts'] as $cart) 
            OrderDetails::create([
            'order_id' => $order_id,
            'product_id' => $cart['id'],
            'qty' => $cart['qty'],
            'unite_price' => $cart['price'],
            ]);






            share|improve this answer























            • unfortunately it doesn't work.

              – Mizanur Rahman
              Mar 26 at 8:53











            • @MizanurRahman It should work. Perhaps you'd share more information?

              – Styx
              Mar 26 at 8:54















            0














            First, you're calling form.post wrong. Second parameter is not additional data, but config options for axios.request call.



            In order to send carts array you should add it to the form itself:



            form: new Form(
            'name': '',
            'phone': '',
            'address':'',
            'pro_id' : [],
            'qty' : [],
            'unit_price' : [],
            'carts' : [], // <-- added
            ),


            Then, replace usage of carts with form.carts in your template (and methods).



            Now, carts will be sent to the server along with other data.



            And lastly, you don't need to use json_decode at all.



            //...
            $data = $this->validate($request, [
            'name' => 'required',
            'phone' => 'required',
            'address' => 'required',
            'carts' => 'required|array',
            'carts.*.name' => 'string',
            'carts.*.id' => 'integer',
            'carts.*.qty' => 'integer',
            'carts.*.price' => 'numeric',
            ]);


            Then, you can use $data as a source of data.



            foreach ($data['carts'] as $cart) 
            OrderDetails::create([
            'order_id' => $order_id,
            'product_id' => $cart['id'],
            'qty' => $cart['qty'],
            'unite_price' => $cart['price'],
            ]);






            share|improve this answer























            • unfortunately it doesn't work.

              – Mizanur Rahman
              Mar 26 at 8:53











            • @MizanurRahman It should work. Perhaps you'd share more information?

              – Styx
              Mar 26 at 8:54













            0












            0








            0







            First, you're calling form.post wrong. Second parameter is not additional data, but config options for axios.request call.



            In order to send carts array you should add it to the form itself:



            form: new Form(
            'name': '',
            'phone': '',
            'address':'',
            'pro_id' : [],
            'qty' : [],
            'unit_price' : [],
            'carts' : [], // <-- added
            ),


            Then, replace usage of carts with form.carts in your template (and methods).



            Now, carts will be sent to the server along with other data.



            And lastly, you don't need to use json_decode at all.



            //...
            $data = $this->validate($request, [
            'name' => 'required',
            'phone' => 'required',
            'address' => 'required',
            'carts' => 'required|array',
            'carts.*.name' => 'string',
            'carts.*.id' => 'integer',
            'carts.*.qty' => 'integer',
            'carts.*.price' => 'numeric',
            ]);


            Then, you can use $data as a source of data.



            foreach ($data['carts'] as $cart) 
            OrderDetails::create([
            'order_id' => $order_id,
            'product_id' => $cart['id'],
            'qty' => $cart['qty'],
            'unite_price' => $cart['price'],
            ]);






            share|improve this answer













            First, you're calling form.post wrong. Second parameter is not additional data, but config options for axios.request call.



            In order to send carts array you should add it to the form itself:



            form: new Form(
            'name': '',
            'phone': '',
            'address':'',
            'pro_id' : [],
            'qty' : [],
            'unit_price' : [],
            'carts' : [], // <-- added
            ),


            Then, replace usage of carts with form.carts in your template (and methods).



            Now, carts will be sent to the server along with other data.



            And lastly, you don't need to use json_decode at all.



            //...
            $data = $this->validate($request, [
            'name' => 'required',
            'phone' => 'required',
            'address' => 'required',
            'carts' => 'required|array',
            'carts.*.name' => 'string',
            'carts.*.id' => 'integer',
            'carts.*.qty' => 'integer',
            'carts.*.price' => 'numeric',
            ]);


            Then, you can use $data as a source of data.



            foreach ($data['carts'] as $cart) 
            OrderDetails::create([
            'order_id' => $order_id,
            'product_id' => $cart['id'],
            'qty' => $cart['qty'],
            'unite_price' => $cart['price'],
            ]);







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 25 at 15:30









            StyxStyx

            5,89762839




            5,89762839












            • unfortunately it doesn't work.

              – Mizanur Rahman
              Mar 26 at 8:53











            • @MizanurRahman It should work. Perhaps you'd share more information?

              – Styx
              Mar 26 at 8:54

















            • unfortunately it doesn't work.

              – Mizanur Rahman
              Mar 26 at 8:53











            • @MizanurRahman It should work. Perhaps you'd share more information?

              – Styx
              Mar 26 at 8:54
















            unfortunately it doesn't work.

            – Mizanur Rahman
            Mar 26 at 8:53





            unfortunately it doesn't work.

            – Mizanur Rahman
            Mar 26 at 8:53













            @MizanurRahman It should work. Perhaps you'd share more information?

            – Styx
            Mar 26 at 8:54





            @MizanurRahman It should work. Perhaps you'd share more information?

            – Styx
            Mar 26 at 8:54













            0














            I had been done it in other way. Not using vform i used axios. but i want to done it using vform.



            return
            field: 'name',
            query: '',
            form:
            'name': '',
            'phone': '',
            'address':''
            ,
            products:[],
            carts:[],
            pagination:
            current_page: 1


            store()
            let client =
            cli: this.form

            let data =
            carts: this.carts


            this.$Progress.start()
            axios.post('api/pos', data, client)
            .then( res =>
            this.$Progress.finish()
            console.log(res)
            )
            .catch( e =>
            this.$Progress.fail()
            console.log(e)
            )




            Controller:



            $carts = json_decode($request->getContent('client','data'), true);

            $customer = $carts['client'];
            $pro_info = $carts['data'];

            foreach ($customer as $cus)
            $order = new OrderMaster;
            $order->name = $cus['name'];
            $order->phone = $cus['phone'];
            $order->address = $cus['address'];
            $order->save();



            $order_id = DB::getPdo()->lastInsertId();

            foreach ($pro_info as $cart)
            foreach ($cart as $c)
            OrderDetails::create([
            'order_id' => $order_id,
            'product_id' => $c['id'],
            'qty' => $c['qty'],
            'unit_price' => $c['price'],
            ]);







            share|improve this answer





























              0














              I had been done it in other way. Not using vform i used axios. but i want to done it using vform.



              return
              field: 'name',
              query: '',
              form:
              'name': '',
              'phone': '',
              'address':''
              ,
              products:[],
              carts:[],
              pagination:
              current_page: 1


              store()
              let client =
              cli: this.form

              let data =
              carts: this.carts


              this.$Progress.start()
              axios.post('api/pos', data, client)
              .then( res =>
              this.$Progress.finish()
              console.log(res)
              )
              .catch( e =>
              this.$Progress.fail()
              console.log(e)
              )




              Controller:



              $carts = json_decode($request->getContent('client','data'), true);

              $customer = $carts['client'];
              $pro_info = $carts['data'];

              foreach ($customer as $cus)
              $order = new OrderMaster;
              $order->name = $cus['name'];
              $order->phone = $cus['phone'];
              $order->address = $cus['address'];
              $order->save();



              $order_id = DB::getPdo()->lastInsertId();

              foreach ($pro_info as $cart)
              foreach ($cart as $c)
              OrderDetails::create([
              'order_id' => $order_id,
              'product_id' => $c['id'],
              'qty' => $c['qty'],
              'unit_price' => $c['price'],
              ]);







              share|improve this answer



























                0












                0








                0







                I had been done it in other way. Not using vform i used axios. but i want to done it using vform.



                return
                field: 'name',
                query: '',
                form:
                'name': '',
                'phone': '',
                'address':''
                ,
                products:[],
                carts:[],
                pagination:
                current_page: 1


                store()
                let client =
                cli: this.form

                let data =
                carts: this.carts


                this.$Progress.start()
                axios.post('api/pos', data, client)
                .then( res =>
                this.$Progress.finish()
                console.log(res)
                )
                .catch( e =>
                this.$Progress.fail()
                console.log(e)
                )




                Controller:



                $carts = json_decode($request->getContent('client','data'), true);

                $customer = $carts['client'];
                $pro_info = $carts['data'];

                foreach ($customer as $cus)
                $order = new OrderMaster;
                $order->name = $cus['name'];
                $order->phone = $cus['phone'];
                $order->address = $cus['address'];
                $order->save();



                $order_id = DB::getPdo()->lastInsertId();

                foreach ($pro_info as $cart)
                foreach ($cart as $c)
                OrderDetails::create([
                'order_id' => $order_id,
                'product_id' => $c['id'],
                'qty' => $c['qty'],
                'unit_price' => $c['price'],
                ]);







                share|improve this answer















                I had been done it in other way. Not using vform i used axios. but i want to done it using vform.



                return
                field: 'name',
                query: '',
                form:
                'name': '',
                'phone': '',
                'address':''
                ,
                products:[],
                carts:[],
                pagination:
                current_page: 1


                store()
                let client =
                cli: this.form

                let data =
                carts: this.carts


                this.$Progress.start()
                axios.post('api/pos', data, client)
                .then( res =>
                this.$Progress.finish()
                console.log(res)
                )
                .catch( e =>
                this.$Progress.fail()
                console.log(e)
                )




                Controller:



                $carts = json_decode($request->getContent('client','data'), true);

                $customer = $carts['client'];
                $pro_info = $carts['data'];

                foreach ($customer as $cus)
                $order = new OrderMaster;
                $order->name = $cus['name'];
                $order->phone = $cus['phone'];
                $order->address = $cus['address'];
                $order->save();



                $order_id = DB::getPdo()->lastInsertId();

                foreach ($pro_info as $cart)
                foreach ($cart as $c)
                OrderDetails::create([
                'order_id' => $order_id,
                'product_id' => $c['id'],
                'qty' => $c['qty'],
                'unit_price' => $c['price'],
                ]);








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 26 at 9:25

























                answered Mar 26 at 9:01









                Mizanur RahmanMizanur Rahman

                276




                276



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326767%2fhow-to-pass-array-data-from-vuejs-to-laravel-api-controller%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현