关于 php:Laravel modal binding 给出 route not found 错误 | 珊瑚贝

Laravel modal binding gives route not found error


我正在使用 laravel 4.2 开发简单的粗略应用程序。这是我用于编辑/更新的控制器方法。

1
2
3
4
5
6
7
8
class ProductsController extends BaseController{

    public function getEdit($id){

       $product=Products::find($id);
       $this->layout->content=View::make(‘products.edit’,compact(‘product’));  
   }
}

这是edit.blade.php文件的一部分

1
 {{ Form::model($product, [‘route’ => [‘products/update’, $product->id], ‘method’ => ‘patch’]) }}

我在 route.php 文件中为 ProductsController 定义路由如下

1
 Route::controller ( ‘products’, ‘ProductsController’);

当我尝试编辑产品时(http://localhost:8000/products/5/edit)

它说 Route [products/update] 未定义。

这是我的编辑链接

1
 id . ‘/edit’) }}“>Edit

这个错误的原因是什么?我在产品控制器上定义了 patchUpdate() 函数。


您使用的是路由控制器,而不是资源丰富的控制器 – 所以没有”命名”路由。

你可以这样做

1
{{ Form::model($product, [‘action’ => ‘ProductsController@putEdit’, $product->id], ‘method’ => ‘patch’]) }}
  • 我尝试使用 products.update。但后来它说”找不到控制器方法”浏览器链接是 localhost:8000/products/3/edit
  • 是的,同意@TheShiftExchange 使用下面提到的模型路线或资源路线
  • 仍然给出相同的错误”找不到控制器方法”。我的路由 URL 是否正确?本地主机:8000/products/2/edit


在你的 routes.php 文件中添加下面一行

1
2
Route::model(‘products’, ‘Product’);
Route::resource(‘products’, ‘ProductsController’);

并更改@The Shift Exchange 的建议

1
products.update not products/update

也改变

1
 id) }}“>Edit
  • 仍然给出相同的错误”找不到控制器方法”。我的路由 URL 是否正确?本地主机:8000/products/2/edit
  • 刚刚编辑的答案。您是否在 routes.php 文件中添加了上述代码
  • 也改变 id) }}”>编辑
  • 改变了提到的每一件事。但它不起作用
  • 您是否创建了我和 TheShiftExchange 建议的方法编辑或 putEdit,您将在其中放置更新代码
  • 如果您想重定向到相同的方法,请将编辑更改为 getEdit (‘products/getEdit/’.$product->id)


来源:https://www.codenong.com/28380536/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9375.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?