我有一个Laravel 5.2网站,上传了多个文件。我有一个文件删除按钮无法正常工作。用户只是重定向回页面,但文件仍然存在。
show.blade
<div class="row">
<form class="col-xs-2" method="POST" action="/exception/{{$truckingDelivery->exception->id}}">
{!! csrf_field() !!}
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="fa fa-times pull-left" id="deleteFileButton"></button>
</form>
<a class="col-xs-10" href="{{$truckingDelivery->exception->path}}" target="_blank">View Exception</a>
</div>
routes.php文件
Route::delete('/exception/{id}','TruckingDeliveryController@deleteException');
例外模式
public function delete(){
\File::delete([
$this->path,
$this->name
]);
parent::delete();
}
货运交付模式
public function exception()
{
return $this->hasOne('App\Exception', 'trucking_delivery_id');
}
货运交付控制器
public function deleteException($id){
$exception = Exception::findOrFail($id)->delete();
return back();
}
答案 0 :(得分:0)
destroy是直接删除实体的正确方法(通过对象或模型)。
public function deleteException($id){
$exception = Exception::destroy($id);
return back();
}