0

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.

Rafaeatul
  • 43
  • 8
  • You should check the server logs (Apache or nginx and php). – Rouhollah Mazarei Apr 18 '19 at 05:24
  • Just add statement ```print_r($request->all());exit;``` in the top of the method ```store``` and check are you getting the data exactly you've posted in request? It seems ```call_detail_id``` is not there in ```this.call_detail``` you're posting. Also check storage/logs for the error log. – Dev Apr 18 '19 at 05:30
  • i have tried print_r, dd, return to see if the data is getting properly. but the page is loading in vue component and i cant find the printr or dd or return anywhere on the page – Rafaeatul Apr 18 '19 at 05:36
  • Error 500 requires you read the serve apache error log. Report back with your findings and someone can help further. Also during your debug I suggest xdebug in this case or try using dump as an alternative to dd (dont use print_r) this is Laravel not 1999. I assure you the answer is in the log. – GingaWRATH Apr 18 '19 at 07:57

0 Answers0