我創建了一個表格,我試圖提交數據,但錯誤:MethodNotAllowedHttpException在RouteCollection.php行218:試圖提交數據
MethodNotAllowedHttpException in RouteCollection.php line 218:
即將到來。該怎麼辦?
歡迎刀片:
@extends('layouts.master')
@section('title')
Welcome!!
@endsection
@section('content')
@include('includes.message-block')
<div class="row">
<div class="col-md-6">
<h2>Enter Your Information</h2>
<form action="" method="post">
<div class="form-group" {{$errors -> has('name') ? 'has-error': ''}}>
<label for="name">Name</label>
<input class="form-control" type="text" name="name" id="name" placeholder="Your name">
</div>
<div class="form-group" {{$errors -> has('email') ? 'has-error': ''}}>
<label for="email">Email-Id</label>
<input class="form-control" type="email" name="email" id="email" placeholder="Enter Your Email Id">
</div>
<div class="form-group">
<label for="branch">Branch</label>
<input class="form-control" type="text" name="branch" id="branch" placeholder="Enter Your Branch">
</div>
<div class="form-group">
<label for="course_name">Course Name</label>
<input class="form-control" type="text" name="course_name" id="course_name" placeholder="Enter Your Course">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<input type="hidden" name="_token" value="{{Session::token()}}">
</form>
</div>
@endsection
型號:
<?php
namespace App;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
class User extends Model implements Authenticatable
{
use \Illuminate\Auth\Authenticatable;
protected $table = 'students';
}
UserController中:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
//use Illuminate\Support\Facades\Flash;
use InvalidConfirmationCodeException;
use Flash;
//use Mail;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersstudents;
class UserController extends Controller
{
public function postData(Request $request)
{
$this -> validate($request,[
'email' => 'required|email|unique:students',
'name' => 'required|max:20',
'branch' => 'required|max:10'
'course_name' => 'required|max:10'
]);
$email = $request['email'];
$name = $request['name'];
$branch = $request['branch'];
$course_name = $request['course_name'];
$student = new User();
$student->email =$email;
$student->name = $name;
$student->branch = $branch;
$student->course_name = $course_name;
$student->save();
return redirect()->back();
}
}
路線/ web.php:
Route::group(['middleware' => ['web']], function(){
Route::get('/', function() {
return view('welcome');
});
Route::post('/submit_data',[
'uses' => '[email protected]',
'as' => 'submit_data'
]);
});
遷移:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('students', function (Blueprint $table) {
$table->increments('id');
$table->string('mail')->unique();
$table -> string('name');
$table -> string('branch');
$table -> string('course_name');
$table->rememberToken();
$table->timestamps();
});
}
public function down()
{
Schema::drop('students');
}
}
我的遷移名爲create_users_table。我不明白爲什麼會出現這個錯誤。這是一種簡單易用的形式。只需填寫一份簡單的表格即可提交學生數據,並將其保存在數據庫中。
你'action'支撐在'<形式行動=「」方法=「郵報」 >'是空的,你應該嘗試添加你配置的路由:'