Laravel将控制器重定向到带有var的控制器

时间:2017-05-10 10:27:37

标签: php laravel laravel-5

我试图将控制器重定向到控制器,但我在RouteCollection.php第218行获取MethodNotAllowedHttpException:错误,我似乎无法弄清楚是什么错误

commentcontroller:

<?php

namespace App\Http\Controllers;


use Session;

use Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class commentcontroller extends Controller
{

    public function create()
    {
    $linked_to_post = Request::input('linked_to_post');
    $creator_id = Request::input('creator_id');
    $comment = Request::input('comment');
    DB::table('comments')->insert(['linked_to_post'=>$linked_to_post,'creator_id'=>$creator_id,'content'=>$comment]);


return redirect()->action('postcontroller@post', ['redirectid' => $linked_to_post]);
    }

PostController中:

<?php

namespace App\Http\Controllers;
use App\Users;
use Session;
use App\posts;
use Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class postcontroller extends Controller
{


public function post(){
    if (isset($redirectid)) {
        $currentid = $redirectid;
    }else{
$currentid = request::input('hiddenpostid');

    }

       $users = users::getusers();
       $posts = posts::getposts();
       foreach ($posts as $post) {
        if ($currentid == $post->post_id) {
           $currentpost = $post;
        }
          }




    return view('post',['posts'=>$currentpost]);
   }

路线:

Route::get('/', function () {
    return view('welcome');
});
Route::get('new','productcontroller@product');
Route::get('admin','admincontroller@authenticate');
Route::get('blog','postcontroller@index');
Route::post('createpost','postcontroller@create');
Route::post('registeruser','usercontroller@create');
Route::post('loginuser','usercontroller@login');
Route::post('logoutuser','usercontroller@logout');
Route::post('post','postcontroller@post');
Route::post('submitcomment','commentcontroller@create');

1 个答案:

答案 0 :(得分:0)

您正在尝试重定向到POST路线。重定向会发出GET个请求。

因此,如果您没有为MethodNotAllowedHttpException uri设置GET方法路线,则会获得/post