Home Ask Login Register

Developers Planet

Your answer is one click away!

Santiago Muñoz February 2016

Call to a member function fill() on null

I want to do an update keeping the following information:

$radicado = \App\Radicado::find($id);
        $radicado->codigoRadicado = $request['codigoRadicado'];
        $radicado->Dependencia_idDependencia = $request['Dependencia_idDependencia'];
        $radicado->Serie_idSerie = $request['Serie_idSerie'];
        $radicado->SubSerie_idSubSerie = $request['SubSerie_idSubSerie'];
        return response()->json(['message' => 'Actualizado correctamente']);

    return redirect('/radicado');

and for this run the following ajax

var token = document.getElementById('token').value;
        async: true,
        headers: {'X-CSRF-TOKEN': token},
        url: $(formId).attr('action'),
        type: $(formId).attr('method'),
        data: $(formId).serialize(),
        dataType: 'html',
        success: function(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


patricus February 2016

The first two lines shown are this:

$radicado = \App\Radicado::find($id);

The error is because your find() statement did not find a record with that $id. Since it did not find a record, it returns null. Since it returns null, $radicado is now null, and you cannot call methods on a null value.

Ralph John Galindo February 2016

Make sure first that the row exists. Try firstOrFail()

$radicado = \App\Radicado::firstOrFail($id);

If its still not working, double check your facade or model.

Post Status

Asked in February 2016
Viewed 3,331 times
Voted 12
Answered 2 times


Leave an answer

Quote of the day: live life