0π
Itβs fine using foreach as long all data you want is available like the key
to put the id of authenticated user in employee_id just put this one
Auth::id();
and put it above your code
use Auth;
0π
I managed to make it work, somehow this syntax works. Hopefully someone could enlighten me more about this.
Controller.php
public function store(Request $request)
// This works
foreach($request->rows as $data) {
$test = new EmployeeObjective;
$test->employee_id = $request->id;
$test->kpa_info = $data['kpa'];
$test->save();
// This does not work
foreach($request->rows as $data) {
EmployeeObjective::updateOrCreate([
'employee_id' => $request->id,
'kpa_info' => $data['kpa'],
Now here is the tricky part. I saved the data from the $store
to my local object and passed it during the save method.
Component.vue
created () {
this.auth = this.$store.state.authUser.id
},
save () {
axios.post('/api/employee-objective', {
rows: this.rows,
id: this.auth
})
.then(res => { console.log(res) })
.catch(err => { console.log(err) });
}
Source:stackexchange.com