You shouldn't use a link to delete records, you need to use a form and do a post request. Anyway The id you are passing into your method doesn't exist in the table in the database, that is why you get that kind of error.
Getting 'Call to a member function delete() on null' error when deleting record
Hello, im in the early stage of learning, so please enlightened me.
I'm encountering an issue while attempting to delete a record in my Laravel application. The problem is leading to the following error message: "Call to a member function delete() on null"
In my controller, I have a method intended to delete a record associated with a specific "patient" ID. The method looks like this:
delete controller
public function deleteAntenatal($id)
{
Antenatal::find($id)->delete();
return redirect()->route('listAntenatal');
}
view
<a href="{{ route('deleteAntenatal', $anc->id) }}" class="btn btn-danger">
<i><i class="fa fa-trash"></i></i>
</a>
While attempting to delete the record with a specific "patient" ID, I'm encountering the "Call to a member function delete() on null" error. Could the presence of the related "patient" ID be causing this issue? If so, how can I address this error and successfully delete the associated record?
Please or to participate in this conversation.