(php,laravel) how to delete multi images with its path in laravel

雨燕双飞 提交于 2021-01-29 20:15:06

问题


database

id.   project_id.    type.      images
1.      23.         frontend    3344.png
2.      23.         frontend.   3326.png
3.      23.         er diagram  4290.png
4.      23          wireframe.  995.png
5.      23.         wireframe.  8875.png

view blade

@foreach($project_data as $project)
                    <td> 
                    <a title="delete" href="javascript:void(0);" class="confirmDelete" name="project_data" record="delete_project" recordid="{{$project['id']}}" style="color: red"><i class="fas fa-trash"></i></a> 
                      </td>
@endforeach 

route

Route::get('delete_project/{id}','ProjectDataController@deleteProject');

controller

public function deleteProject($id){
  $project_items = ProjectImages::select('images')->where('project_id',$id)->first();
 
     $project_image_path_front = 'hash images/project images/frontend/';
     $project_image_path_er = 'hash images/project images/er diagram/';
     $project_image_path_wire = 'hash images/project images/wireframe/';

  
    if(file_exists($project_image_path_front.$project_items->images)){
        unlink($project_image_path_front.$project_items->images);
    }
    if(file_exists($project_image_path_er.$project_items->images)){
        unlink($project_image_path_er.$project_items->images);
    }
    if(file_exists($project_image_path_wire.$project_items->images)){
        unlink($project_image_path_wire.$project_items->images);
    }
     ProjectImages::where('project_id',$id)->delete();
 }

how to delete the image from the database and from its path also this code only delete the first image which is mentioned in the database

来源:https://stackoverflow.com/questions/64920122/php-laravel-how-to-delete-multi-images-with-its-path-in-laravel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!