Laravel8で開発していて、ふと、こんなエラーが出ました。
Call to a member function delete() on null
ソースコードはこんな感じなのですが、
public function error_del($id){
$ErrorLog = ErrorLog::find($id);
$ErrorLog->delete();
}
すぐにわかったのが、別のモデルのIDを渡していた。
ということがエラーの原因でした。
The cause of the error was passing the ID of another model.
正しいIDを渡すとエラーが解消されました。
Passing the correct ID cleared the error.