I want to loop through the array and insert them into the database. When i check dd($request->users), it displays "NULL" but if i put dd($request->all()), the data array appears. Plus the code for controller below doesn't insert the data into the database. Thanks
Script
<script>
export default {
data(){
return{
users: [{
username:'',
password:'',
phone:'',
email:''
}]
}
},
methods:{
addMoreData(){
this.users.push({
username: '',
password: '' ,
email: '',
phone:''
});
},
deleteData(index){
this.users.splice(index,1)
},
submitData(){
axios.post('/api/user', this.users)
}
},
mounted() {
console.log('Component mounted.')
}
}
Controller
public function store(Request $request)
{
for ($i = 1; $i < count($request->all()); $i++) {
data::create([
'username'=>$request->username[$i],
'password'=>$request->password[$i],
'phone'=>$request->phone[$i],
'email'=>$request->email[$i]
]);
}
}
Edited

$user = User::create([..]). Can you writedd($request->all())and display result here?