Laravel URL Route 获取 2 个参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26979979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:26:19  来源:igfitidea点击:

Laravel URL Route get 2 parameter

laravellaravel-4laravel-routing

提问by GandhyOnly

I need to delete a photo from an Album so I think I need 2 parameter on Routing but I get some error please give me solution or another way to delete a photo from an album

我需要从相册中删除照片,所以我想我需要在路由上使用 2 个参数,但是我遇到了一些错误,请给我解决方案或从相册中删除照片的其他方法

here's my Routes.php :

这是我的 Routes.php :

Route::get('/admin/album/{albumid}/{id}/delete-photo', array(
    'as' => 'admin-photo-delete',
    'uses' => 'GalleryController@deletePhoto'
));

and call a function deletePhoto on GalleryController, here's GalleryController :

并在 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');}

and here how I call route :

在这里我如何调用 route :

 <a href="{{URL::route('admin-photo-delete',$id,$photo->id)}}">Delete Photo</a>

I already make sure that $id and $photo->id was not null but see what url showing there's no second parameter value so I get some error: enter image description here

我已经确保 $id 和 $photo->id 不为空,但是看看哪个 url 显示没有第二个参数值,所以我得到了一些错误: 在此处输入图片说明

回答by Luís Cruz

In URL::route, you should use an array as the second parameter, like this:

在 中URL::route,您应该使用数组作为第二个参数,如下所示:

<a href="{{URL::route('admin-photo-delete', [$id, $photo->id] )}}">Delete Photo</a>