[英]Call to a member function fill() on null
I want to do an update keeping the following information: 我要进行更新,保留以下信息:
$radicado = \App\Radicado::find($id);
$radicado->fill($request->all());
$radicado->codigoRadicado = $request['codigoRadicado'];
$radicado->Dependencia_idDependencia = $request['Dependencia_idDependencia'];
$radicado->Serie_idSerie = $request['Serie_idSerie'];
$radicado->SubSerie_idSubSerie = $request['SubSerie_idSubSerie'];
$radicado->save();
if($request->ajax())
{
return response()->json(['message' => 'Actualizado correctamente']);
}
return redirect('/radicado');
and for this run the following ajax 为此运行以下ajax
var token = document.getElementById('token').value;
$.ajax({
async: true,
headers: {'X-CSRF-TOKEN': token},
url: $(formId).attr('action'),
type: $(formId).attr('method'),
data: $(formId).serialize(),
dataType: 'html',
success: function(result){
$(formId)[0].reset();
alert(result);
document.getElementById("preview").style.display = "none";
},
error: function(){
alert('No se ha actualizado el documento.');
}
});
But when I get this error store: Call to a member function fill() on null 但是,当我得到此错误存储时:在null上调用成员函数fill()
The first two lines shown are this: 显示的前两行是这样的:
$radicado = \App\Radicado::find($id);
$radicado->fill($request->all());
The error is because your find()
statement did not find a record with that $id
. 错误是因为您的
find()
语句未找到带有该$id
的记录。 Since it did not find a record, it returns null
. 由于未找到记录,因此返回
null
。 Since it returns null
, $radicado
is now null
, and you cannot call methods on a null
value. 由于它返回
null
,因此$radicado
现在为null
,并且您不能在null
值上调用方法。
Make sure first that the row exists. 首先确保该行存在。 Try
firstOrFail()
试试
firstOrFail()
$radicado = \App\Radicado::firstOrFail($id);
If its still not working, double check your facade or model. 如果仍然无法使用,请仔细检查您的外观或模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.