簡體   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