Ogün ADSAY
Ogün ADSAY

Reputation: 63

MethodNotAllowedHttpException in RouteCollection.php line 219 general error

There are a lot of people having this issue and there are some solutions but i just couldn't resolve mine.Codes are down there. when i go localhost:8000/article i get my articles. There is no problem. I can go /article/create. But when submit i get MethodNotAllowedHttpException in RouteCollection.php line 219 error. when i go article/2 i get MethodNotAllowedHttpException in RouteCollection.php line 219 error.

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','PagesController@about');
Route::get('contact','PagesController@contact');

Route::get('article','ArticleController@index');
Route::get('article/create','ArticleController@create');
Route::get('article/{id}','ArticleController@show');

Route::post('article','ArticleController@store');

EDIT 1 php artisan route:list output here:

GET|HEAD | about | App\Http\Controllers\PagesController@about    
GET|HEAD | article | App\Http\Controllers\ArticleController@index  
GET|HEAD | article/create | App\Http\Controllers\ArticleController@create 
GET|HEAD | contact | App\Http\Controllers\PagesController@contact

EDIT 2 and SOLUTION

with php artisan route:clear clear your route list and do php artisan route:list you will get your all routes. it worked fine for me.

Upvotes: 1

Views: 171

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163768

Try to change this in create.blade.php:

{!! Form::open(['url' => 'article']) !!}

to this:

{!! Form::open(array('route' => 'article.store')) !!}

UPDATE

Run php artisan route:clear to clear routes cache.

Upvotes: 1

Related Questions