2016-07-01 16 views
2

Laravelのブログプロジェクトpostcontrollerのgetメソッドは動作していますが、postメソッドは機能しません。私はPostメソッドをリダイレクトします。しかしAccordind私の私のコードにはpage.Myコントローラコードは、私のルートはLaravel Post ControllerメソッドとPostControllerが動作しない

<?php 


Route::group(['middleware' => ['web']], function() { 

    Route::group([ 
     'prefix' =>'/admin' 
     ], function() { 
      Route::get('/', [ 
       'uses' => '[email protected]', 
       'as' => 'admin.index' 
      ]); 

      Route::get('/blog/posts/create', [ 
        'uses' => '[email protected]', 
        'as' => 'admin.blog.create_post' 
      ]); 

      Route::get('/blog/post/create', [ 
        'uses' => '[email protected]', 
        'as' => 'admin.blog.post.create' 
      ]); 
     }); 
}); 

私のフォームは

​​

私は私のポストを提出されたファイル

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 

use App\Post; 
use App\Category; 

class PostController extends Controller 
{ 

    public function getBlogIndex() { 
     return view('frontend.blog.index'); 
    } 

    public function getSinglePost($post_id,$end='frontend') { 
     return view($end . '.blog.single'); 
    } 

    public function getCreatePost() { 
     return view('admin.blog.create_post'); 
    } 

    public function postCreatePost(Request $request) { 
     $this->validate($request, [ 
      'title' => 'required|max:120|unique:posts', 
      'author' => 'required|max:80', 
      'body' => 'required' 
      ]); 

     $post = new Post(); 
     $post->title = $request['title']; 
     $post->author = $request['author']; 
     $post->body = $request['body']; 
     $post->save(); 

     return redirect()->route('admin.index')->with(['success' => 'Post Successfully Created']); 
    } 
} 

である私の管理者に返す必要があります私はこれを示します enter image description here

私は問題がどこにあるかを見つけません。 PlzヘルプMe

答えて

4

これは、非常に一般的なエラーであり、慎重に考えてください。あなたが見るたびに:あなたは確認する必要があり

MethodNotAllowedHttpException

RouteCollection.php

で非常に最初の事はあなたが正しくあなたがしようとしているものに基づいて Route::getまたは Route::postを持っていることを確認するために、ルートファイルです行う。

あなたのフォームはデータをPOSTとして送信しますが、経路はGETです。

<form action="{{ route('admin.blog.post.create') }}" method="post"> 

Route::get('/blog/post/create', [ 
    'uses' => '[email protected]', 
    'as' => 'admin.blog.post.create' 
]); 

Route::postにそれが正しく機能するためにその変更。

+0

ご協力ありがとうございます。問題は解決された。 –

+0

@ Jahid26これが問題を正しく解決した場合は、これを選択された回答としてマークしてください。 –

関連する問題