ming_aud

109 经验值

@JellyBool

已经解决了

factory(Articleurl::class, 30)->create(); // 这样就不行

factory(\App\Articleurl::class, 30)->create(); //这样就成功了。。

不知道为什么。。。。

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),
    ];
});

首先,权限系统参考http://9iphp.com/web/laravel/laravel-5-acl-define.html该文章编写的。 Model: CommonUser.php <?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; class CommonUser extend