rafliaryansyah's avatar

why the file is uploaded when it fails or errors add data

when it fails to add data, why does the file upload even though it has been conditioned,

this is an example of my condition code:

if ($request->hasFile('image')) {
    	    $image = $request->file('image')->store('assets/images/highlighs');
        } else {
        	    $image = 'assets/images/highlighs/default.jpg';
        }

   $highlight->image = $image;

guess what is missing or wrong? thank you

0 likes
3 replies
a4ashraf's avatar

@rafliaryansyah

actually $request->hasFile('image') return true if your file field not empty

make sure that your request->file should empty if you are not selecting any file

try with this and see if your file field have the image

dd($request-all())
1 like
rafliaryansyah's avatar

array:5 [ "type" => "2" "status" => "1" "headline" => "Headbang" "services" => array:1 [] "image" => Illuminate\Http\UploadedFile {#1365} ]

it is the response given, and it is true that the file was uploaded despite an error

rafliaryansyah's avatar

means that one solution is to condition the file request? but the strangest thing is that when the process adds data and there is an error the file keeps uploading, is there a solution?

Please or to participate in this conversation.