1. Migration声明的表结构
Schema::create('article_urls', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('body');
$table->string('url_link');
$table->integer('user_id')->unsigned();
$table->integer('last_user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
2.以下为 ModelFactory.php 文件内的代码
$factory->define(App\User::class, function (Faker\Generator $faker) {
return [
'username' => $faker->username,
'email' => $faker->email,
'avatar' =>$faker->imageUrl(256,256),
'password' => bcrypt(str_random(10)),
'remember_token' => str_random(10),
];
});
$factory->define(App\Article_url::class, function (Faker\Generator $faker) {
$user_ids = \App\User::lists('id')->toArray();
return [
'title' => $faker->sentence,
'body' => $faker->paragraph,
'url_link' => $faker->sentence,
'user_id' => $faker->randomElement($user_ids),
'last_user_id' => $faker->randomElement($user_ids),
];
});