Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用更新Ajax-Laravel的空请求_Php_Jquery_Ajax_Laravel_Laravel 5 - Fatal编程技术网

Php 使用更新Ajax-Laravel的空请求

Php 使用更新Ajax-Laravel的空请求,php,jquery,ajax,laravel,laravel-5,Php,Jquery,Ajax,Laravel,Laravel 5,我正试图用ajax修改数据库,但当我发送信息时,它在插入时给我以下错误,好像请求是空的: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'date' cannot be null (SQL: update `appointments` set `date` = , `startTime` = , `finalTime` = , `user_id` = , `patient_id` = , `updated_at` = 2

我正试图用ajax修改数据库,但当我发送信息时,它在插入时给我以下错误,好像请求是空的:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'date' cannot be null (SQL: update `appointments` set `date` = , `startTime` = , `finalTime` = , `user_id` = , `patient_id` = , `updated_at` = 2017-10-03 18:05:40 where `id` = 32)
这是控制器:

 public function update(Request $request, $id)
{
    $appointment =Appointment::find($id);
    $appointment->patient_id = $request->patient_id;
    $appointment->user_id = $request->user_id;
    $appointment->date = $request->date;
    $appointment->startTime = $request->startTime;
    $appointment->finalTime = $request->finalTime;

    $appointment->save();
}
路线:

Route::name('appointments.update')->put('/citas/{id}', 'AppointmentController@update'); 
阿贾克斯:


看起来您的
$中可能有错误。ajax
数据
字段当前为
日期
,应该是:

$.ajax({
    url: update_url,
    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
    type:'PUT',
    data:{user_id:user_id, patient_id:patient_id, date:date, startTime:startTime, finalTime:finalTime},
    success:function(result){
        alert('success');
    },
    error:function(result){
        alert('error');
    }

});

根据错误,您将以null.dd($request->all()的形式发送日期,并向我们所有人发布结果。
$.ajax({
    url: update_url,
    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
    type:'PUT',
    data:{user_id:user_id, patient_id:patient_id, date:date, startTime:startTime, finalTime:finalTime},
    success:function(result){
        alert('success');
    },
    error:function(result){
        alert('error');
    }

});