Laravel TokenMismatchException [英] Laravel TokenMismatchException
本文介绍了Laravel TokenMismatchException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在,我正在学习laravel,但我一直在接受这种药物:
Right now I'm learing laravel but I keep getting the exeption:
VerifyCsrfToken.php第53行中的TokenMismatchException:
TokenMismatchException in VerifyCsrfToken.php line 53:
我试图创建一个迁移对象,然后将其写入数据库,但是由于某种原因,它无法正常工作.这是我的route.php:
I'm trying to make an object of a migration and then write it to the database but for some reason it's not working. This is my route.php:
Route::get('/post/new',array(
'uses'=> 'blog@newPost',
'as' => 'newPost'
));
Route::post('/post/new', array (
'uses' => 'blog@createPost',
'as' => 'createPost'
));
这是我的名为blog.php的控制器:
This is my controller called blog.php:
使用Illuminate \ Http \ Request;
use Illuminate\Http\Request;
use App\Http\Requests;
use View;
use App\Http\Controllers\Controller;
use App\posts;
class blog extends Controller
{
public function newPost()
{
return View::make('new');
}
public function createPost()
{
$posts = new posts();
$posts->title = Input::get('title');
$posts->content = nl2br(Input::get('content'));
$posts->save();
}
}
这是迁移:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts',function($table) {
$table->increments('id');
$table->string('title');
$table->text('content');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
schema::drop('posts');
}
}
这是我的主要观点:
@extends('master')
@section('content')
<h3>Add a blog post</h2>
<form action="{{ URL::route('createPost') }}" method="post">
<div class="form-group">
<input name="title" class="form-control" type="text" placeholder="title"/>
</div>
<div class="form-group">
<textarea name="content" class="form-control" placeholder="write here"> </textarea>
</div>
<input type="submit" class="btn btn-primary" />
</form>
@stop
可能是什么问题?
推荐答案
在表单的结束标记之前添加以下行:
Add this line before the closing tag of your form:
{{ Form::token() }}
这篇关于Laravel TokenMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文