0

我正在尝试使用 laravel 控制器将一些数据从我的 vue 组件发送到数据库。为了避免空白输入错误,我已经将我的所有表格列都设为空,除了 ID。仍然当我尝试使用 post 方法发送数据时,我收到错误 500。

这是我的Vue方法:

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));
            }



        }

这是我从 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

        }
    }

这是我在 api.php 中的路线

Route::post('video_call', 'VideoCallController@store');

最后是控制器中的存储功能:

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);
        }

    }

我在以前的应用程序中使用这种方法将数据从 vue 发送到数据库,并且效果很好。在这个应用程序中它返回错误。

4

0 回答 0