简体   繁体   English

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

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

I've created a resource 我创建了一个资源

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

code in view: 查看代码:

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

and my edit method in PageCategoryController.php 和我在PageCategoryController.php编辑方法

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

when i click the button in the view it redirectes to my 404 view. 当我单击视图中的按钮时,它将重定向到我的404视图。 When i hover over the button the link is like http://localhost:8000/page-category//edit . 当我将鼠标悬停在按钮上时,链接就像http://localhost:8000/page-category//edit When i manually insert id number in link http://localhost:8000/page-category/1/edit it does takes me to edit page. 当我在链接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>

What if your controller becomes: 如果您的控制器变为:

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

So this will send the $pcategory , in this case your page category with the id ( $id ), to your view. 因此,这会将$pcategory (在本例中为ID为( $id )的页面类别)发送到视图。

From there you'll be able access to your route page-category.edit by sending it the id of the page category: $pCategory->id just like you did. 从那里您可以通过发送页面类别的ID来访问您的路线page-category.edit category.edit: $pCategory->id ,就像您所做的一样。

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

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