我在我的网站上的个人资料页上有删除按钮。我想要它从存储中删除图像,并将数据库中的'person‘字段中的值改为default.png。
我尝试向我的按钮添加动作,该按钮引用路由并使用控制器中的deleteImage函数。所有内容都包含在代码中。
我的代码中的按钮,用于删除图像:
<a href="" action="{{$person->last_name}}/delete" id="" class="tabledit-delete-button btn btn-danger waves-effect waves-light active" name="delete-image" id="delete-image-button">
<i class="icofont icofont-ui-delete"></i></a>具有路由的web.php:
Route::get('/person/profile/{person_id}/{last_name}/delete', 'Views\Person\PersonViewController@deleteImage')->name('deleteImage');PersonViewController.php中的函数
function deleteImage($id)
{
$name = Person::where('person_id', $id)->get('avatar');
if(Storage::delete('/files/assets/images/user-profile/' . $name, '/files/assets/images/user-profile/standard/' . $name, '/files/assets/images/user-profile/miniatures/' . $name) && Person::where('person_id', $id)->update(['avatar' => 'default.png'])) {
return view('person.profile.profile-view')->with('success', 'Image Deleted Successfully');
}
else{
return view('person.profile.profile-view')->with('fail','Something Went Wrong');
}
}我想要的按钮,以删除图像存储在3个文件夹/files/assets/images/user-profile/,/files/assets/images/user-profile/standard,/files/assets/images/user-profile/mimiature,也改变了在数据库中的值从imagename到default.png
发布于 2019-05-18 18:23:04
你可以像这样更改函数名吗,function deleteImage($id, $lastName) ,然后注释函数中的所有代码,然后放入 $variables = [$id, $lastName] dd($variables)。
https://stackoverflow.com/questions/56185005
复制相似问题