Search
 
SCRIPT & CODE EXAMPLE
 

PHP

when image update laravel delete remove image

public function update(Post $post){
    $this->validateRequest();
    $data = [
        'title' => request()->title,
        'content' => request()->content
    ];
    if (request()->hasFile('image') && request('image') != '') {
        $imagePath = public_path('storage/'.$post->image);
        if(File::exists($imagePath)){
            unlink($imagePath);
        }
        $image = request()->file('image')->store('uploads', 'public');
        $data['image'] = $image;
        $post->update($data);
    }
    $post->update($data);
}
Comment

Delete an image laravel

//On top
use IlluminateSupportFacadesStorage;

//then
if(Storage::exists('your/path'.$file_name)){
  Storage::delete('your/path'.$file_name);
  /*
    Delete Multiple File like this way
    Storage::delete(['path/example.png', 'path/example2.png']);
  */
  return true;
}
Comment

PREVIOUS NEXT
Code Example
Php :: php remove execution time limit 
Php :: uuid package generator laravel 
Php :: laravel blade if variable exist 
Php :: How to always use ignore-platform-reqs flag when running composer? 
Php :: must be an instance of IlluminateHttpRequest 
Php :: php max_execution_time 
Php :: php mysql date 
Php :: select case default php 
Php :: for php 
Php :: wordpress https too many redirects 
Php :: cast array to object php 
Php :: php json_encode encode not escape forward slash 
Php :: laravel eloquent get 10 records 
Php :: php mysql insert data 
Php :: woocommerce terms and condition fields checked by default 
Php :: php mysql connect 
Php :: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress. 
Php :: get post order by meta value int 
Php :: php get uploaded file extension 
Php :: cut string in php 
Php :: setup_postdata not working 
Php :: php get extension from string 
Php :: wordpress on publish hook 
Php :: php remove all but numbers 
Php :: destroy session php 
Php :: laravel sum group by 
Php :: delete property from object php 
Php :: laravel route list only api 
Php :: laravel get latest record by date 
Php :: php sleep milliseconds 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =