I want to store data from array to my Database. My code looks like this:
Vue.js
const self = this;
fetch('/api/store/devices',{
method: 'post',
body: JSON.stringify(self.devices),
headers: {
'content-type': 'application/json'
}
})
.then(res => res.json())
.then(data => {
console.log(data);
// do something
})
.catch(err => console.log(err));
}
API Route
Route::post('store/devices',[App\Http\Controllers\StorageController::class, 'store']);
StorageController.php
public function store(Request $request)
{
//Go to array and save data
}
The data i overget looks like this:
[
{device_id: "1245678", storage_id: 1},
{device_id: "8784889", storage_id: 1},
{device_id: "8457875", storage_id: 1}
]
How can i store this data?