douba9020 2016-06-18 17:55
浏览 99
已采纳

RouteCollection.php Laravel中的MethodNotAllowedHttpException

I have problem to save name and email from user1 in table user1s that I have made .

When I enter them in textareas using html form in Laravel with route::post and function store it is not working. When I enter text and hit the button Register it outputs the following error:

MethodNotAllowedHttpException in RouteCollection.php line

You will see that I use the HTML form and that I have tried to add <input ....> into my form.


Here are my files:

route.php

<?php

Route::get('/','PageController@home');
Route::post('/','User1Controller@store');

Route::get('about','PageController@about');

welcome.blade.php

I'm not sure about the action. After putting user1 inf into table, it should be redirected to a "Thank you" page (I have a thankyou.blade.php ) , maybe that is the problem

<form  method="POST" action=""> 
                    <input name="_token" type="hidden" value="{{ csrf_token() }}"/>

                <ul class="list-group" >


                    <li  >
                    NAme
                    <div class="form-group" title="email" >
                        <textarea name="name" class="form-control" >

                        </textarea>
                    </div>
                    </li  >

                    <li>Email
                    <div class="form-group" > 
                        <textarea name="email"  class="form-control" >

                        </textarea>
                    </div>
                    </li>

                    <li  >
                        <div class="form-group" >
                        <button class="btn btn-primary">Register</button>
                        </div>
                    </li>

                </ul>
            </form>

migration for user1

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateNotesTable extends Migration
{

    public function up()
    {
        Schema::create('notes', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('card_id')->unsigned();
            $table->text('body');            
            $table->timestamps();
        });
    }


    public function down()
    {
        Schema::drop('notes');
    }
}

user1controller.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User1;

class User1Controller extends Controller
{

    public function store(Request $request)
        {

            $user= new User1;
            $user->name = $request->name;
            $user->email =  $request->email;
            $user->save();

            return view('thankyou');

        }

}

pagecontroller.php

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

use App\User1;

class PageController extends Controller
{
    public function home()
    {
            $user1s= User1::all();
    return view('welcome',compact('user1s'));
    }

    public function about()
    {
            return view('pages.about'); 
    }

}
  • 写回答

3条回答 默认 最新

  • doudou5421 2016-06-18 19:39
    关注

    Your form is basically a registration form. I would recommend using a more meaningful name for the end point. The post route can be something like,

    Route::post('/register','User1Controller@store');
    

    Now the form action can be,

    action="/register"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多尺度特征图提取和融合
  • ¥15 微信小程序:渲染收货地址时页面不显示
  • ¥20 win7 64位DirectShow提示初始化失败如何解决?
  • ¥20 小规模孤立词识别系统设计
  • ¥15 关于Java对接海康威视车牌识别一体机SDK是否需要固定外网的IP?
  • ¥15 Linux扩容时,格式化卡住了:vgdispaly查看卷组信息,没有输出
  • ¥18 关于#ubuntu#的问题:使用背景-工作职责内有七八台ubuntu系统的电脑,平时需要互相调取资料,想实现把这几台电脑用交换机组成一个局域网,来实现指定文件夹的互相调取和写入
  • ¥20 求一个简易射频信号综测仪
  • ¥15 esp8266 tally灯 接收端改为发射端
  • ¥30 Labview代码调用access 数据库,相同代码其中一个调用不出来是为什么