很多人都懂一些简单的电脑系统问题的解决方案,但是swiftbic的解决思路却鲜为人知,小编前几天就遇到了swiftbic的问题,于是准备整理一些swiftbic的解决思路,其实只需要按照1:首先说说laravel框架的安装,这里我使用的是composer进行安装,如果对安装有疑惑的话, 请自己解决. composer create-project --prefer-dist laravel/laravel laravel2:其次配置数据库连接信息,对应的文件在 /Users/maogou/work/laravel/.env 然后把对应的数据库用户名,密码,数据库等信息填写正确的步骤即可,大家一起来看看小编整理的关于swiftbic的解决方法:
1:首先说说laravel框架的安装,这里我使用的是composer进行安装,如果对安装有疑惑的话, 请自己解决.
composer create-project --prefer-dist laravel/laravel laravel
2:其次配置数据库连接信息,对应的文件在
/Users/maogou/work/laravel/.env
然后把对应的数据库用户名,密码,数据库等信息填写正确
3:生成对应的控制器和Model文件
php artisan make:controller DemoController
#加-m表示同时生成数据库迁移文件
php artisan make:model Models/Demo -m
4:设计对应的表字段, 这里我只是演示数据填充的使用,所以尽量多的使用多的字段的使用来演示.编辑对应的数据库迁移文件
<?php
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class CreateDemosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('demos', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('age');
$table->string('password');
$table->string('img');
$table->string('mobile');
$table->string('bank');
$table->string('address');
$table->string('century');
$table->string('city');
$table->string('chrome');
$table->string('country');
$table->string('companyEmail');
$table->string('email');
$table->string('countryCode');
$table->string('citySuffix');
$table->string('creditCardNumber');
$table->string('creditCardDetails');
$table->string('date');
$table->string('domainName');
$table->string('firstName');
$table->string('internetExplorer');
$table->string('word');
$table->string('words');
$table->string('userAgent');
$table->string('unixTime');
$table->string('streetAddress');
$table->string('title');
$table->string('slug');
$table->string('swiftBicNumber');
$table->string('windowsPlatformToken');
$table->string('sha1');
$table->string('sha256');
$table->string('shuffle');
$table->string('safeEmail');
$table->string('safeHexColor');
$table->string('rgbCssColor');
$table->string('safari');
$table->string('ipv4');
$table->string('localIpv4');
$table->string('macAddress');
$table->string('url');
$table->string('monthName');
$table->longText('content');
$table->smallInteger('status');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::drop('demos');
}
}
5:修改对应的Model,填写对应的可填充字段和非可填充字段等
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
use IlluminateSupportFacadesDB;
class Demo extends Model
{
//数据表的名字
protected $table = 'demos';
//使用create_at和update_at字段
public $timestamps = true;
//可以填充的字段
protected $fillable = [
'name',
'age',
'password',
'img',
'mobile',
'bank',
'address',
'century',
'city',
'chrome',
'country',
'companyEmail',
'email',
'countryCode',
'citySuffix',
'creditCardNumber',
'creditCardDetails',
'date',
'domainName',
'firstName',
'internetExplorer',
'word',
'words',
'userAgent',
'unixTime',
'streetAddress',
'title',
'slug',
'swiftBicNumber',
'windowsPlatformToken',
'sha1',
'sha256',
'shuffle',
'safeEmail',
'safeHexColor',
'rgbCssColor',
'safari',
'ipv4',
'localIpv4',
'macAddress',
'url',
'monthName',
'content',
'status',
];
//受保护的字段-这个字段不可写入
protected $guarded = ['id'];
}
6:修改数据填充工厂文件(我习惯这样叫)对应文件在
/Users/maogou/work/laravel/database/factories/ModelFactory.php
然后把数据填充文件中的User填充范例复制一份如下$factory->define(AppModelsDemo::class, function (FakerGenerator $faker) {
return [
'name' => $faker->name,
'age' => $faker->numberBetween(15,90),
'password'=>str_random(6),
'img'=>$faker->imageUrl(),
'mobile' => $faker->phoneNumber,
'bank'=>$faker->bank,
'address'=>$faker->address,
'century'=>$faker->century,
'city'=>$faker->city,
'chrome'=>$faker->chrome,
'country'=>$faker->country,
'companyEmail'=>$faker->companyEmail,
'email'=>$faker->email,
'countryCode'=>$faker->countryCode,
'citySuffix'=>$faker->citySuffix,
'creditCardNumber'=>$faker->creditCardNumber,
'creditCardDetails'=>json_encode($faker->creditCardDetails),
'date'=>$faker->date('Y-m-d H:i:s','now'),
'domainName'=>$faker->domainName,
'firstName'=>$faker->firstName,
'internetExplorer'=>$faker->internetExplorer,
'word'=>$faker->word,
'words'=>$faker->words(5,true),
'userAgent'=>$faker->userAgent,
'unixTime'=>$faker->unixTime,
'streetAddress'=>$faker->streetAddress,
'title'=>$faker->sentence,
'slug'=>$faker->slug(20,false),
'swiftBicNumber'=>$faker->swiftBicNumber,
'windowsPlatformToken'=>$faker->windowsPlatformToken,
'sha1'=>$faker->sha1,
'sha256'=>$faker->sha256,
'shuffle'=>$faker->shuffle('abcdefghijklmnopqrst'),
'safeEmail'=>$faker->safeEmail,
'safeHexColor'=>$faker->safeHexColor,
'rgbCssColor'=>$faker->rgbCssColor,
'safari'=>$faker->safari,
'ipv4'=>$faker->ipv4,
'localIpv4'=>$faker->localIpv4,
'macAddress'=>$faker->macAddress,
'url'=>$faker->url,
'monthName'=>$faker->monthName,
'content'=>$faker->text(500),
'status' => random_int(0,1),
];
});
7:执行数据库迁移生成对应的数据库表
php artisan migrate
8:然后我们去artisan的交互控制台去执行对应的命令,在这个交互控制台你可以执行任何合法的php代码,包括laravel里面的代码
1.修改
/Users/maogou/work/laravel/vendor/fzaninotto/faker/src/Faker/Factory.php
的为const DEFAULT_LOCALE = 'en_US';
const DEFAULT_LOCALE = 'zh_CN';
2. 复制
/Users/maogou/work/laravel/vendor/fzaninotto/faker/src/Faker/Provider/en_US/Text.php
到zh_CN目录下
3. 并把对应的命名空间的名称修改为namespace FakerProviderzh_CN;
php artisan tinker
factory(AppModelsDemo::class,50)->create();
4.查看数据库已经生成了对应的50条测试数据
9:问题总结, 如果你用的是Laravel的5.3的版本, 想要插入中文的测试数据,会发生如下的报错信息, 解决方法参考第六步.