UrlGenerationException:缺少必需的参数[路线:topics.update] [URI:主题/ {}话题]
我得到这个错误:UrlGenerationException:缺少必需的参数[路线:topics.update] [URI:主题/ {}话题]
Missing required parameters for [Route: topics.update] [URI: topics/{topic}]. (View: C:\xampp\htdocs\phpboards\resources\views\topics\edit.blade.php)
这是链接,将采取用户编辑:
<a href="/boards/topics/edit/{{$topic->id}}" class="btn btn-default">Edit</a>
这是编辑控制器:
$topic = Topic::find($id);
return view('topics.edit')->with('topic', $topic);
这是路线:
Route::get('/boards/topics/edit/{id}', '[email protected]');
这是编辑的形式:
<div class="container">
{!! Form::open(['action' => '[email protected]', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('title', 'Title') }}
{{ Form::text('title', $topic->topic_title, ['class' => 'form-control', 'placeholder' => 'Title of the Post']) }}
</div>
<div class="form-group">
{{ Form::label('desc', 'Desc') }}
{{ Form::textarea('desc', $topic->topic_body, ['class' => 'form-control', 'placeholder' => 'Description of the Post']) }}
</div>
{{ Form::submit('Submit', ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
</div>
我做了什么错在这里?
相反的:
{!! Form::open(['action' => '[email protected]', 'method' => 'POST']) !!}
使用
{!! Form::open(['url' => route('topics.update', $topic->id), 'method' => 'POST']) !!}
,因为你的路线,你需要传递要更新的话题ID。此外,使用named routes代替Controller @ method表示法更合理。
是的,它工作。谢啦。 –
让我们承认您的update()
方法已经在您的TopicController上实现。
首先需要声明另一条路线:
Route::put('/boards/topics/edit/{id}', '[email protected]');
// ^^^
然后通过这个改变你的模子开口:
{!! Form::open(['action' => ['[email protected]', $topic->id], 'method' => 'put']) !!}
// ^^^^^^^^^^ ^^^
它应该工作。
同样的错误.. –
你确定你已经修改了你的'Form :: open'参数吗?试试这个命令:'artisan route:clear && artisan cache:clear' –
上面的解决方案工作。我没有通过帖子的ID。这是创建错误。 –
@ParantapParashar但是对于什么?并为哪个控制器? –
你的代码有太多的错误。 –
我认为你必须把你的更新方法和路线放在这里。 –