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 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn