Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mdabutaleb's avatar

How do i permanently delete a soft deleted item?

My code does not work:)

public function destroy($id) { $obj = Upload::destroy($id); }

0 likes
8 replies
mdabutaleb's avatar

in this case what is $flight variable? is it object of my Model?

tomopongrac's avatar

Here is from documentation

$flight = App\Flight::find($id);

$flight-> forceDelete();
2 likes
mdabutaleb's avatar

My model name is : "Upload" and i'm trying to permanent delete using the following way:

public function destroy($id) { $myItem = Upload::find($id); $myItem->forceDelete(); }

But through an error which is : FatalThrowableError in UploadController.php line 119: Call to a member function forceDelete() on null

tomopongrac's avatar

Do you get any result from this

$myItem = Upload::find($id);
dd($myItem);
mdabutaleb's avatar
mdabutaleb
OP
Best Answer
Level 1

Thank you very much ! It's working by the following way:

public function destroy($id) { $flight = Upload::where('id', $id)->forcedelete(); }

5 likes
yanikkumar's avatar

[Update] For some people who still are struggling today. You need to get the $flight item this way:

 $flight = Upload::withTrashed()->find($id);

and then force Delete

$flight->forceDelete();

If you get the flight this way: $flight = Upload::findOrFail($id); it will always return null as the item has been soft deleted.

1 like

Please or to participate in this conversation.