(php,laravel)如何删除多个图像及其在laravel中的路径
数据库(php,laravel)如何删除多个图像及其在laravel中的路径,php,laravel,image,Php,Laravel,Image,数据库 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 视图
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
视图刀片
@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
控制器
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();
}
如何从数据库及其路径中删除图像
此代码仅删除数据库中提到的第一个图像
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();
}