I got this error:
Non-static method IlluminateDatabaseEloquentModel::delete() should not be called statically, assuming $this from incompatible context
Here is the code in my controller:
JavaScript
x
$file_db = new File();
$file_db = $file_db->where('id',$id)->find($id);
$file_db = $file_db->delete();
Can someone explain what I am doing wrong and how to call it correctly?
Advertisement
Answer
You have this:
JavaScript
$file_db = $file_db->where('id',$id)->find($id);
But you should be doing this:
JavaScript
$file = File::where('id', $id)->first(); // File::find($id)
if($file) {
return $file->delete();
}