我是laravel新手..我试图实现一个简单的博客网站。 index.blade.php的代码如下:laravel表单问题MethodNotAllowedHttpException错误
@foreach ($articles as $article)
<div align = "center">
<h2>{{ $article->title }}</h2>
<div>{{ $article->text }}</div>
{{ Form::open(array('route' => array('articles.show', $article->id))) }}
{{ Form::submit('SHOW') }}
{{ Form::close() }}
{{ Form::open(array('method' => 'DELETE', 'route' => array('articles.destroy', $article->id))) }}
{{ Form::submit('DELETE') }}
{{ Form::close() }}
</div>
@endforeach
ArticlesController的代码:
public function show($id)
{
$article = Article::find($id);
return View::make('articles.show', compact('article'));
}
public function destroy($id)
{
Article::destroy($id);
return Redirect::route('articles.index');
}
show.blade.php的代码:
<p>
<strong>Title:</strong>
{{ $article->title }}
</p>
<p>
<strong>Text:</strong>
{{ $article->text }}
</p>
{{ link_to_route('articles.index', 'Back') }}
{{ link_to_route('articles.edit', 'Edit', $article->id) }}
当我点击删除按钮,事情很好。我可以删除文章。但是当我点击显示按钮时,我得到了MethodNotAllowedHttpException错误。 如果我更改了index.blade.php代码:
{{ Form::open(array('route' => array('articles.show', $article->id))) }}
{{ Form::submit('SHOW') }}
{{ Form::close() }}
到
{{ link_to_route('articles.show', 'Show', $article->id) }}
一切顺利。任何人都可以告诉我我的表单有什么问题吗?提前致谢!