douying4909 2016-03-07 10:15
浏览 55

Laravel 5.2:RouteCollection.php第219行中的MethodNotAllowedHttpException

I want to save one form data through my task controller. But when i go to url to access my form. it's showing the following Error:

MethodNotAllowedHttpException in RouteCollection.php line 219:

Here is my Routes.php

<?php
    Route::group(['middleware' => 'web'], function () {
    Route::auth();

  Route::get('/', function () {
    return view('welcome');
    });

    Route::get('/all_item','TestController@index');
    Route::post('/create_item','TestController@create');
    Route::get('/home', 'HomeController@index');
});

Here is my TaskController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Test;
use App\Http\Requests;
use Redirect;

class TestController extends Controller
{
   public function index()
    {
            $alldata=Test::all();
    //      return $alldata;
            return  view('test.itemlist',compact('alldata'));
    }


    public function create()
    {
            return view('test.create_item');
    }


    public function store(Request $request)
    {       
            $input = $request->all();
            Test::create($input);       
            return redirect('test');

    }   
}

Here is the create_item page( post form / view page)

@extends('layouts.app')
@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">Create Item</div>
                {!! Form::open(array('route' => 'Test.store','class'=>'form-horizontal','method' => 'patch'))  !!}
                {!! Form::token(); !!}
                  <?php echo csrf_field(); ?>
        <div class="form-group">
          <label>Item Code</label>
          <input type="text" name="item_code" class="form-control"  placeholder="Code">
        </div>
        <div class="form-group">
          <label>Item Name</label>
          <input type="text" name="item_name" class="form-control"  placeholder="Name">
        </div>        
        <button type="submit" class="btn btn-default">Submit</button>
               {!! Form::close() !!}
            </div>
        </div>
    </div>
</div>
@endsection
  • 写回答

3条回答 默认 最新

  • douji1999 2016-03-07 10:22
    关注

    You're using PATCH method in form, but route with POST method

    try

    'method' => 'patch'
    

    change to

    'method' => 'post'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭