Gan*_*nly 0 laravel laravel-4 laravel-routing
我需要删除相册中的照片,所以我认为我需要2个参数路由但我收到一些错误请给我解决方案或其他方式从相册中删除照片
这是我的Routes.php:
Route::get('/admin/album/{albumid}/{id}/delete-photo', array(
'as' => 'admin-photo-delete',
'uses' => 'GalleryController@deletePhoto'
));
Run Code Online (Sandbox Code Playgroud)
并在GalleryController上调用函数deletePhoto,这是GalleryController:
public function deletePhoto($albumID,$photoID){
$photo = Album::find($albumID)->photo()->where('id','=',$photoID)->get();
if($photo){
File::delete(public_path().'/assets/images/gallery/'.$photo->images);
$photo->delete();
return Redirect::route('admin-gallery')->with('message','Photo was deleted successfully');
}
return Redirect::route('admin-gallery')->with('message','Photo delete failed');}
Run Code Online (Sandbox Code Playgroud)
在这里我如何称呼路线:
<a href="{{URL::route('admin-photo-delete',$id,$photo->id)}}">Delete Photo</a>
Run Code Online (Sandbox Code Playgroud)
我已经确定$ id和$ photo-> id不是null但是看看哪个url显示没有第二个参数值所以我得到一些错误:
在URL::route
,您应该使用数组作为第二个参数,如下所示:
<a href="{{URL::route('admin-photo-delete', [$id, $photo->id] )}}">Delete Photo</a>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11571 次 |
最近记录: |