Insert Record from Ajax post.

Posted 5 days ago by jhutto

I have tried everything I have read but I still can't insert a record from the ajax post response. I keeps giving me server error 500. I have confirmed that the ajax post call is working, because I can

I know the data is coming over because if I comment out the $input = request()->all(); and change the return to.... return json_encode($input); I get the json response back in the console. So, I know it's hitting the controller and responding.

I have tried inserting the data using this method... 'RegistrationID'=> = $request->input('registrationid');

Everything I tried gives me the server error which means that it didn't complete the tasks of inserting. I have also confirmed the line...

$StudentPayments = SomasStudentPayment::where('RegistrationID','=', 13939)->get(); is working because it returns all the payments for this record..

Please help... I'm pulling my hair out over this.... Thanks.

Here's my controller:

public function makepayment(Request $request)
        //$input = request()->all();
        //$RegID = $request->input('registrationid');
       // $PaymentType = $request->input('paymentType');
       // $Checknum = $request->input('checknum');
       // $PaymentAmount = $request->input('paymentamount');

        $StudentPayment = new SomasStudentPayment([
                'RegistrationID'=> $request->get('registrationid'),
                'PaymentTypeID' => $request->get('paymentType'),
                'PaymentDate' => Carbon::now(),
                'CheckNum' => $request->get('checknum'),
                'PaymentAmount' => $request->get('paymentamount'),


        $StudentPayments = SomasStudentPayment::where('RegistrationID','=', 13939)->get();

        return json_encode($StudentPayments);

        $('#StudentPayment').submit(function (e) {
                e.preventDefault(); //**** to prevent normal form submission and page reload
                var $form_data = {};
                $form_data._token = $('meta[name="csrf-token"]').attr('content');
                $form_data.registrationid = $("input#RegID").val();
                $form_data.paymentType = $("select#PaymentType").val();
                $form_data.checknum = $("input#CheckNum").val();
                $form_data.paymentamount = $("input#PaymentAmount").val();
                        url: "/somaspayments/payment",
                        type: "POST",
                        dataType: 'json',
                        data: $form_data,
                        cache: false,
                        success: function (data) {
                                //alert('Your data updated');
                                //return data;
                            error: function () {
                                alert('error handing here');


Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.