Im Moment bin ich learing Laravel aber ich bekomme immer die Ausnahme:Laravel TokenMismatchException
TokenMismatchException in VerifyCsrfToken.php Linie 53:
Ich versuche, ein Objekt einer Migration zu machen und dann schreibe es in die Datenbank, aber aus irgendeinem Grund funktioniert es nicht. Das ist mein route.php:
Route::get('/post/new',array(
'uses'=> '[email protected]',
'as' => 'newPost'
));
Route::post('/post/new', array (
'uses' => '[email protected]',
'as' => 'createPost'
));
Dies ist mein Controller genannt blog.php:
Verwendung Illuminate \ Http \ anfordern;
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();
}
}
Dies ist die Migration:
<?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');
}
}
Und das ist meine Hauptansicht:
@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
Was könnte falsch sein?
Danke für Ihre Antwort. Das klappt leider nicht. – Jamie
Dies ist eine andere Option: '{!! csrf_field() !!} 'Probieren Sie es aus, wie @JaviStolz vorgeschlagen hat. – Michel
danke, das funktioniert! Jetzt sagt es mir: Klasse 'App \ Http \ Controller \ Input' nicht gefunden – Jamie