dougong2306 2018-02-04 16:34
浏览 54
已采纳

传递参数以在控制器中创建操作

I am having issues getting the page to render when using a parameter in a create controller. My show controller works but my create controller doesn't. The error thrown is a 404.

Sorry, the page you are looking for could not be found.

The URL is: http://myapp.test/country/us/state/create

My controller looks like:

// Show
public function show(Country $country, State $state){
  return view('state.show', compact('state'));
}
// Create
public function create(Country $country) {
  return view('state.create', compact('country'));
}

My route looks like:

Route::get('country/{country}/state/{state}', 'StateController@show');
Route::get('country/{country}/state/create', 'StateController@create');
  • 写回答

1条回答 默认 最新

  • doutui6241 2018-02-04 17:03
    关注

    You need to flip your routes around to be

    Route::get('country/{country}/state/create', 'StateController@create');
    Route::get('country/{country}/state/{state}', 'StateController@show');
    

    Laravel processes routes in the order that they are defined, so in your current code Laravel was seeing create as a state.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?