DEV Community

Abolhasan Momeni
Abolhasan Momeni

Posted on

Input type “file” returns EMPTY in Laravel php

Suppose
We have some photos that need to be updated
The user wants to delete one of the files while editing,
How do you know user has sent a NULL input file or not changes?
becuse Input type “file” returns EMPTY ,
So we have two similar state,
for example:
if($request->hasFile('filename')) {
//here is!!! ok you update the file
}else{
//but here not ok,
if you check input exist ,it does not solve the problem
}

how you handle this!

Top comments (2)

Collapse
 
lito profile image
Lito • Edited

Create a checkbox input to mark photo to de deleted:

<input type="checkbox" name="delete" value="1" />
Enter fullscreen mode Exit fullscreen mode

And in the backend service:

if ($request->hasFile('filename')) {
    $this->update()
} elseif ($request->input('delete')) {
    $this->delete();
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
pudgeline profile image
Abolhasan Momeni

good idea,thank's

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay