有很多人有這個問題,有一些解決方案,但我不能解決mine.Codes在那裏。當我去localhost:8000 /文章我得到我的文章。沒有問題。我可以去/文章/創建。但是,當提交我在RouteCollection.php行219錯誤中得到MethodNotAllowedHttpException。當我去文章/ 2我在RouteCollection.php行219錯誤中得到MethodNotAllowedHttpException。RouteCollection.php中的MethodNotAllowedHttpException行219一般錯誤
ArticleController.php
<?php
namespace App\Http\Controllers;
use App\Article;
//use Illuminate\Http\Request;
use Request;
use App\Http\Requests;
class ArticleController extends Controller
{
public function index(){
$articles = Article::all();
return view('articles.index',compact('articles'));
}
public function show($id){
$article = Article::findOrFail($id);
return view('articles.show',compact('article'));
}
public function create(){
return view('articles.create');
}
public function store(){
$input = Request::all();
return $input;
}
}
create.blade.php
@extends('app')
@section('content')
<h1>Write a New Article</h1>
<br/>
{!! Form::open(['url' => 'article']) !!}
<div class="form-group">
{!!Form::label('title','Title:')!!}
{!! Form::text('title',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('body','Body:') !!}
{!! Form::textarea('body',null,['class' => 'form-control'])!!}
</div>
<div class="form-group">
{!!Form::submit('Add Article',['class'=> 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
@stop
index.blade.php
@extends('app')
@section('content')
<h1>Articles</h1>
<br/>
<?php foreach ($articles as $article): ?>
<article>
<h2>
<a href="/article/{{$article->id}}">{{$article->title}}</a>
</h2>
<div class="body">{{$article->body}}</div>
</article>
<?php endforeach ?>
@stop
routes.php文件
<?php
Route::get('about','[email protected]');
Route::get('contact','[email protected]');
Route::get('article','[email protected]');
Route::get('article/create','[email protected]');
Route::get('article/{id}','[email protected]');
Route::post('article','[email protected]');
編輯1 php artisan route:list
輸出這裏:
GET|HEAD | about | App\Http\Controllers\[email protected]
GET|HEAD | article | App\Http\Controllers\[email protected]
GET|HEAD | article/create | App\Http\Controllers\[email protected]
GET|HEAD | contact | App\Http\Controllers\[email protected]
EDIT 2和解決方案
與php artisan route:clear
清楚你的路由表,並做php artisan route:list
你會得到你的所有路由。它爲我工作得很好。
您正在請求不支持發佈請求的路由。 Laravel使您能夠在路由中指定您的請求方法。並且不會讓您在需要獲取請求的頁面中請求發佈帖子。並會拋出一個MethodNotFound異常。 –