Laravel: migrate:refresh 无效
Laravel: migrate:refresh deosn't work
我从 udemy.com 学到了 Laravel,但我对 migrate:refresh 命令有疑问。所以,当我尝试使用它时,我会看到信息
Array to string conversion
I try solve my problem so propably I made new mistakes so it's my code:
Into UserTableSeeder
public function run()
{
App\User::create([
'name' => 'Kati',
'email' => 'hello@hello.pl',
'password' => bcrypt('password'),
'admin' => 1
]);
App\Profile::create([
'user_id' => $user->id,
'avatar' => 'link to avatar',
'about' => 'Interested description',
'youtube' => 'youtube.com',
'facebook' => 'facebook.com'
]);
}
迁移
public function up()
{
Schema::create('profiles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->text('about');
$table->string('youtube');
$table->string('facebook');
$table->timestamps();
});
}
和
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->boolean('admin')->default(0);
$table->rememberToken();
$table->timestamps();
});
}
我尝试从 github 克隆我的存储库并刷新,但我遇到了一些问题。
这应该有效:
public function run()
{
$user = App\User::create([
'name' => 'Kati',
'email' => 'hello@hello.pl',
'password' => bcrypt('password'),
'admin' => 1
]);
App\Profile::create([
'user_id' => $user->id,
'about' => 'Interested description',
'youtube' => 'youtube.com',
'facebook' => 'facebook.com'
]);
}
在您的 运行 语句中,您在 App\Profile
创建过程中引用了变量 $user->id
。但是,它还没有实例化。
此外,您正在尝试将头像添加到您的个人资料中,因此您应该将其添加到 Profile
-table 中,或者像我所做的那样,将其从您的播种机中删除。
我在我的播种机中解决了它:
'user_id' =>\App\User::pluck('id')->random();
我从 udemy.com 学到了 Laravel,但我对 migrate:refresh 命令有疑问。所以,当我尝试使用它时,我会看到信息
Array to string conversion I try solve my problem so propably I made new mistakes so it's my code: Into UserTableSeeder
public function run()
{
App\User::create([
'name' => 'Kati',
'email' => 'hello@hello.pl',
'password' => bcrypt('password'),
'admin' => 1
]);
App\Profile::create([
'user_id' => $user->id,
'avatar' => 'link to avatar',
'about' => 'Interested description',
'youtube' => 'youtube.com',
'facebook' => 'facebook.com'
]);
}
迁移
public function up()
{
Schema::create('profiles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->text('about');
$table->string('youtube');
$table->string('facebook');
$table->timestamps();
});
}
和
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->boolean('admin')->default(0);
$table->rememberToken();
$table->timestamps();
});
}
我尝试从 github 克隆我的存储库并刷新,但我遇到了一些问题。
这应该有效:
public function run()
{
$user = App\User::create([
'name' => 'Kati',
'email' => 'hello@hello.pl',
'password' => bcrypt('password'),
'admin' => 1
]);
App\Profile::create([
'user_id' => $user->id,
'about' => 'Interested description',
'youtube' => 'youtube.com',
'facebook' => 'facebook.com'
]);
}
在您的 运行 语句中,您在 App\Profile
创建过程中引用了变量 $user->id
。但是,它还没有实例化。
此外,您正在尝试将头像添加到您的个人资料中,因此您应该将其添加到 Profile
-table 中,或者像我所做的那样,将其从您的播种机中删除。
我在我的播种机中解决了它:
'user_id' =>\App\User::pluck('id')->random();