【发布时间】:2015-03-18 09:50:38
【问题描述】:
我在从数据库中删除时遇到问题。例如,如果我检查了 5 项,则只有一项被删除。 Normaly 脚本是正确的: 我的看法:
{{ Form::open(array('url'=>'/administration/photo/deletePhoto','method' => 'post','files'=>true)) }}
@foreach($aPhotoInCategory as $photo)
{{ HTML::image($photo->name,'alt', array('class'=>'news-content-image','width' => 95, 'height' => 70 )) }}
{{ Form::checkbox('aObjects[]',$photo->id)}}
{{ Form::hidden('id',$aOnePhotoCategory['id']) }}
@endforeach
<br/><br/>
{{ Form::submit('Delete',array('class'=>'btn btn-primary')) }}
{{ Form::close() }}
我的控制器:
public function deletePhoto(){
$aPhotoChecked = Input::get('aObjects');
$id = Input::get('id');
foreach($aPhotoChecked as $photo){
$oPhoto = \Photo::find($photo);
if($oPhoto){
File::delete('public/'.$oPhoto->name);
$oPhoto->delete();
return Redirect::to('administration/category_photo/edit/'.$id)
->with('message_succes','Succes');
}
}
}
数组 $aPhotoChecked 包含所有检查的项目,但是当我按下删除按钮时,只有一个项目被删除,而不是所有检查。 请帮帮我。
【问题讨论】:
标签: laravel laravel-4 laravel-routing laravel-3 laravel-5