I'm learning how to use Laravel and got caught in an encoding problem. I am trying to use tinker to insert data into my tables, and there I am getting the following error when I try to include a new post:
Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xA1tulo ...' for column 'title' at row 1 (SQL: insert into 'posts' ('title', 'body', 'updated_at', 'created_at') values (Título 1, Corpo do primeiro post, 2017-10-09 14:58:40, 2017-10-09 14:58:40))'
My migration responsible for the posts table looks like this:
use Illuminate\Support\Facades\Schema;
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 (Blueprint $table) {
// $table->charset = 'utf8';
// $table->collation = 'utf8_general_ci';
$table->increments('id');
$table->string('title');
$table->mediumText('body');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
I'm using Windows 10, and to run the Laravel commands I'm using the cmder program. Here is an example post insertion I try to do:
$post = new App\post();
$post->title = 'Título 1';
$post->body = 'Corpo do primeiro post';
$post->save();
Could anyone tell me what I can do to insert accented words?