Concept Flow - Deleting files
Start
Check if file exists
Yes
Delete the file
Confirm deletion
End
No
Skip deletion
End
The flow checks if the file exists, deletes it if yes, then confirms deletion or skips if file not found.
<?php use Illuminate\Support\Facades\Storage; if (Storage::exists('file.txt')) { Storage::delete('file.txt'); }
| Step | Action | Check Result | File Exists? | Delete Called? | Outcome |
|---|---|---|---|---|---|
| 1 | Check if 'file.txt' exists | Storage::exists('file.txt') | true | No | Proceed to delete |
| 2 | Call Storage::delete('file.txt') | N/A | true | Yes | File deleted |
| 3 | End process | N/A | N/A | N/A | File no longer exists |
| 4 | If file did not exist | Storage::exists('file.txt') | false | No | Skip deletion and end |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| fileExists | undefined | true | true | false (file deleted) |
| deleteCalled | false | false | true | true |
Laravel file deletion:
- Use Storage::exists('filename') to check file presence
- Use Storage::delete('filename') to remove file
- Always check before deleting to avoid errors
- delete() returns true if deleted, false if not
- Safe and clean file removal in Laravel storage