繁体   English   中英

资源路由(编辑)重定向到404页面的laravel

[英]Resource route (edit ) redirecting to 404 page laravel

我创建了一个资源

Route::resource('page-category', 'PageCategoryController',['except'=>['create'] ]);

查看代码:

<a href="{{ route('page-category.edit',$pcategory->id) }}" class="btn btn-block btn-primary pull-right" style="margin:20px;">Edit</a>

和我在PageCategoryController.php编辑方法

public function edit($id)
{
    $pcategory = PageCategory::find($id);
    return view('admin.page-category.show')->withPcategory($pcategory);
}

当我单击视图中的按钮时,它将重定向到我的404视图。 当我将鼠标悬停在按钮上时,链接就像http://localhost:8000/page-category//edit 当我在链接http://localhost:8000/page-category/1/edit手动插入ID号时,确实需要我编辑页面。

根据https://laravel.com/docs/5.4/controllers#resource-controllers上的路由指南尝试此操作

<a href="{{ route('page-category.edit',['page-category' => $pcategory->id]) }}" class="btn btn-block btn-primary pull-right" style="margin:20px;">Edit</a>

如果您的控制器变为:

public function edit($id) {
    $pcategory = PageCategory::find($id);
    return view('admin.page-category.show')->compact('pcategory');
}

因此,这会将$pcategory (在本例中为ID为( $id )的页面类别)发送到视图。

从那里您可以通过发送页面类别的ID来访问您的路线page-category.edit category.edit: $pCategory->id ,就像您所做的一样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM