In questo momento mi sto istruzionene laravel ma continuo a ricevere l'exeption:laravel TokenMismatchException
TokenMismatchException in linea VerifyCsrfToken.php 53:
Sto cercando di rendere un oggetto di una migrazione e poi scriverlo nel database ma per qualche motivo non funziona. Questo è il mio route.php:
Route::get('/post/new',array(
'uses'=> '[email protected]',
'as' => 'newPost'
));
Route::post('/post/new', array (
'uses' => '[email protected]',
'as' => 'createPost'
));
Questo è il mio controller chiamato blog.php:
uso 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();
}
}
Questa è la migrazione:
<?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');
}
}
e questo è il mio punto di vista principale:
@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
Cosa c'è di sbagliato?
Grazie per la risposta. Sfortunatamente non funziona. – Jamie
Questa è un'altra opzione: '{!! csrf_field() !!} 'Quindi provalo come suggerito da @JaviStolz. – Michel
grazie che funziona! Ora mi sta dicendo: Classe 'App \ Http \ Controllers \ Input' non trovata – Jamie