I am trying to send some data from my vue component to database using a laravel controller. To avoid blank input error, I already made all my table columns nullable except the ID. Still when I am trying to send the data using post method, i am getting error 500.
Here is my vue method:
addRecord(){
fetch('api/video_call', {
method: 'post',
body: JSON.stringify(this.call_detail),
headers: {
'content-type': 'application/json'
}
})
.then(res => res.json())
.then( data=> {
this.call_detail.receiver_caller_id = '';
this.call_detail.sender_caller_id = '';
this.call_detail.receiver_id= '';
this.call_detail.sender_id= '';
this.call_detail.call_received='';
alert('Test Done');
this.fetchCallDetail();
})
.catch(err => console.log(err));
}
}
here is the data that I am returning from vue:
data(){
return {
users: [],
call_details: [],
call_detail: {
id: '',
receiver_caller_id: '',
sender_caller_id: '',
receiver_id: '',
sender_id: '',
call_received: ''
},
call_detail_id: '',
pagination: {},
call_allowed: false
}
}
Here is my route in api.php
Route::post('video_call', 'VideoCallController@store');
And finally here is the store function in controller:
public function store(Request $request)
{
$record = $request->isMethod('put')?VideoCall::findOrFail($request->call_detail_id):new VideoCall;
$record->id= $request->input('call_detail_id');
$record->receiver_id= $request->input('receiver_id');
$record->sender_id= $request->input('sender_id');
$record->sender_call_id= $request->input('sender_call_id');
$record->receiver_call_id= $request->input('receiver_call_id');
$record->call_recieved=$request->input('call_received');
if($record->save())
{
return new VideoCallResource($record);
}
}
I used this methods in my previous apps to send data from vue to database and it worked just fine. In this app it is returning error.