7
I’m learning how to use Laravel and grabbed on to an encoding problem. I’m trying to use the Tinker to insert data into my tables, and there I’m 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 table posts is 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 am using Windows 10, and to run the commands of Laravel I am using the program Cmder. Here’s an example of post insertion I try to do:
$post = new App\post();
$post->title = 'Título 1';
$post->body = 'Corpo do primeiro post';
$post->save();
Would someone tell me what I can do to insert accented words to work?
But his example does not go through the CMD, of course you can be correct, but only if the example of the author of the question is not real and he did not pass the correct details.
– Guilherme Nascimento
Well observed. I imagined that what he posted after Migration was a sequence of commands from
tinker
. As I have been through this, I imagined it would be something like this. But let’s wait for the author clarify.– Guh
The problem only happens in CMD, via personal Tinker. When I run the same code, directly on the pages, everything is ok. It’s funny that on another machine, I asked a friend to take the same test, and it worked on his computer. It’s like my environment is producing this coding conflict. I came to create a project from scratch and repeated the test, and nothing, all in the same. Could be some configuration of my wamp, my operating system, or something external of that kind interfering?
– churros