【问题标题】:Missing required parameters for [Route: posts.update] [URI: posts/{post}][Route: posts.update] [URI: posts/{post}] 缺少必需的参数
【发布时间】:2023-03-23 02:48:01
【问题描述】:

我正在制作一个简单的表单,但出现以下错误:

缺少 [Route: posts.update] [URI: posts/{post}] 的必需参数。 (查看:C:\laragon\www\blog\resources\views\post\edit.blade.php)

{!! Form::model($post, ['action' => 'PostController@update', 'post' => $post]) !!}

从表单将参数添加到控制器的正确方法是什么?

【问题讨论】:

  • 你用的是哪个版本的 laravel?
  • 试试{!! Form::model($post, ['action' => 'PostController@update', 'id' => $post]) !!}。我认为问题在于您正在传递“post”并且控制器可能有一个参数$id

标签: php laravel forms


【解决方案1】:

试试这样:

{!! Form::model($post, ['action' => ['PostController@update', $post->id], 'method' => 'PUT']) !!}

如果您的路线是资源:

路线资源

Route::resource('post','PostController');

表单更新

{!! Form::model($post, ['route' => ['post.update', $post->id], 'method' => 'PUT']) !!}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-22
    • 2022-01-16
    • 2021-03-10
    • 2020-08-17
    • 2021-07-12
    • 2019-01-27
    • 1970-01-01
    相关资源
    最近更新 更多