【问题标题】:Laravel URL Route get 2 parameterLaravel URL Route 获取 2 参数
【发布时间】:2015-01-14 19:05:01
【问题描述】:

我需要从相册中删除一张照片,所以我认为我需要 2 个路由参数 但我遇到了一些错误,请给我解决方案或其他方式从相册中删除照片

这是我的 Routes.php :

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

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

这里我怎么称呼路线:

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

我已经确保 $id 和 $photo->id 不为空,但查看显示没有第二个参数值的 url,所以我得到了一些错误:

【问题讨论】:

  • 在 URL 中,'delete-photo' 之前有 2 个反斜杠

标签: laravel laravel-4 laravel-routing


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-12
    • 2015-12-12
    • 2015-10-19
    • 2019-01-20
    • 2015-07-22
    • 2019-01-20
    • 2014-10-26
    • 2018-07-09
    相关资源
    最近更新 更多