2 years ago

Laravel 5.2 MethodNotAllowedHttpException

Posted 2 years ago by heshammahmoud

I got MethodNotAllowedHttpException error on my Laravel 5.2 project, while I was adding Add Comment section.

Here is my route:

Route::post('/posts/{post}/comments', '[email protected]');

Here is my CommentsController:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post;
use App\Comment;
use App\Http\Requests;

class CommentsController extends Controller
    public function store(Post $post)
            'body' => request('body'),
            'post_id' => $post->id

        return back();

and here is my view:

<div class="col-sm-8 blog-main">
    <h1>{{ $post->title }}</h1>
    {{ $post->body }}
    <div class="comments">
        <ul class="list-group">
            @foreach ($post->comments as $comment)
            <li class="list-group-item">
                {{ $comment->created_at->diffForHumans() }}: &nbsp;
            {{ $comment->body }}
    <!-- Add Comment -->
    <div class="card">
        <div class="card-block">
            <form method="POST" action="/blog/public/posts/{{ $post->id }}/comments" >
                <div class="form-group">
                    <textarea name="body" placeholder="Your Comment" class="form-control"></textarea>
                 <div class="form-group">
                     <button type="submit" class="btn btn-primary">Add Comment</button>

Here is also my project link on GitHub:

Please sign in or create an account to participate in this conversation.