rushand
4 months ago
604
8
Laravel

Internal Server Error

Posted 4 months ago by rushand

Error o Console

VM2397:1 POST http://cms.test/timeslots 500 (Internal Server Error)
(anonymous)	@	VM2397:1
send	@	jquery.min.js:2
ajax	@	jquery.min.js:2
(anonymous)	@	create:604
dispatch	@	jquery.min.js:2
v.handle	@	jquery.min.js:2

View

<script>
$(document).ready(function(){
    $('#create_record').click(function(){
      //  $('#formModal').modal('show');
    $('.modal-title').text("Add New Record");
        $('#action_button').val("Add");
        $('#action').val("Add");
        $('#formModal').modal('show');
     });

$('#sample_form').on('submit', function(event){
 event.preventDefault();
 if($('#action').val() == 'Add')
 {
  $.ajax({
   url:"{{ route('timeslots.store') }}",
   method:"POST",
   data: new FormData(this),
   contentType: false,
   cache:false,
   processData: false,
   dataType:"json",
   success:function(data)
   {
    var html = '';
    if(data.errors)
    {
     html = '<div class="alert alert-danger">';
     for(var count = 0; count < data.errors.length; count++)
     {
      html += '<p>' + data.errors[count] + '</p>';
     }
     html += '</div>';
    }
    if(data.success)
    {
     html = '<div class="alert alert-success">' + data.success + '</div>';
     $('#sample_form')[0].reset();
     $('#user_table').DataTable().ajax.reload();
    }
    $('#form_result').html(html);
   }
  })
 }


});



});
</script>

Controller

    public function store(Request $request){


        $rules = array(
            'title'=>  'required',
             'day'=>  'required',
            'start_time'=>'required',
            'end_time'=>'required',


        );

        $error = Validator::make($request->all(), $rules);

        if($error->fails())
        {
            return response()->json(['errors' => $error->errors()->all()]);
        }


        $form_data = array(
            'title'=>  $request->title,
            'day'=>  $request->day,
            'start_time'=>  $request->start_time,
            'end_time'=>  $request->end_time,


        );

        Timeslot::create($form_data);

        return response()->json(['success' => 'Data Added successfully.']);
    }

All Work and validation error msgs shows successfully Issu is it dosent store any data to the database and return a Server Error on log

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