嗨,我是laravel的新手,我设置了我的安装并添加了旅行者套餐。现在,当我尝试刷新我的数据库CLI:php artisan migrate:refresh --seed
时,我收到此错误消息。
Migrated: 2018_01_24_120417_create_voucher_table
Migrating: 2018_01_29_094240_create_shop_table
Migrated: 2018_01_29_094240_create_shop_table
Migrating: 2018_01_30_085852_create_categorys_table
Migrated: 2018_01_30_085852_create_categorys_table
Seeding: UsersTableSeeder
In Builder.php line 412:
No query results for model [TCG\Voyager\Models\Role].
我可以在哪里找到详细的错误说明以及种子有什么问题?
<?php
use Illuminate\Database\Seeder;
use TCG\Voyager\Models\Role;
use TCG\Voyager\Models\User;
class UsersTableSeeder extends Seeder
{
/**
* Auto generated seed file.
*
* @return void
*/
public function run()
{
if (User::count() == 0) {
$role = Role::where('name', 'admin')->firstOrFail();
User::create([
'name' => 'Admin',
'email' => 'admin@admin.com',
'password' => bcrypt('password'),
'remember_token' => str_random(60),
'role_id' => $role->id,
]);
}
}
}
格拉西亚斯
答案 0 :(得分:1)
你运行php artisan voyager:install --with-dummy
了吗?此命令创建开始使用Voyager
答案 1 :(得分:0)
在run()函数中创建角色:
public function run()
{
if (Role::count() == 0) {
Role::create([
'name' => 'admin',
'display_name' => 'Administrator',
]);
}
if (User::count() == 0) {
$role = Role::where('name', 'admin')->firstOrFail();
User::create([
'name' => 'Admin',
'email' => 'admin@admin.com',
'password' => bcrypt('password'),
'remember_token' => Str::random(60),
'role_id' => $role->id,
]);
}
}