【发布时间】:2014-12-18 21:24:03
【问题描述】:
在 Laravel 中,我试图在我的数据库中植入一些可能包含特殊字符的文本字段。当我执行db:seed 时,它说它成功地为数据库播种,但是当我查看我的数据库时,我看到它插入了除特殊字符之后的文本之外的所有内容(在该字段中)。
这是我的种子的样子:
City::create(array(
'name' => 'Groningen',
'description' => 'A simple description with a special character é in it, and
some content that for some reason won\'t be inserted to my database'
));
所以要明确一点:'é' 之前的文本被插入到数据库中,但它之后的文本不是。所以我的数据库看起来像:
id | name | description
-----|-----------------|-------------------
1 | Groningen | A simple description with a special character
我的城市模型
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class City extends Model {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'cities';
}
我的城市迁移文件:
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCitiesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cities', function($t) {
$t->increments('id');
$t->string('name');
$t->text('description');
$t->double('latitude')->nullable();
$t->double('longitude')->nullable();
$t->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('cities');
}
}
还有我的 config/database.php:
return [
'default' => 'mysql',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'citydb',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
],
// The other Laravel default database.php config
【问题讨论】:
标签: php database laravel model eloquent