php中laravel5.1视频,php – Laravel 5.1中的数据库播种

我正在使用laravel 5.1.我正在尝试运行数据库种子命令.

我的表名是用户

我的迁移文件如下

2015_11_09_194832_create_users_table.php

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::create('users', function (Blueprint $table) {

$table->increments('id');

$table->string('name');

$table->string('email')->unique();

$table->string('password', 60);

$table->rememberToken();

$table->timestamps();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

Schema::drop('users');

}

}

DatabaseSeeder.php

use App\User;

use Illuminate\Database\Seeder;

use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder

{

/**

* Run the database seeds.

*

* @return void

*/

public function run()

{

Model::unguard();

$this->call(UsersTableSeeder::class);

Model::reguard();

}

}

UsersTableSeeder.php

// DatabaseSeeder.php

use App\User;

use Illuminate\Database\Seeder;

use Illuminate\Database\Eloquent\Model;

class UsersTableSeeder extends Seeder

{

/**

* Run the database seeds.

*

* @return void

*/

public function run()

{

Model::unguard();

DB::table('users');

$users = array(

['name' => 'Ryan Chenkie', 'email' => 'ryanchenkie@gmail.com', 'password' => Hash::make('secret')],

['name' => 'Chris Sevilleja', 'email' => 'chris@scotch.io', 'password' => Hash::make('secret')],

['name' => 'Holly Lloyd', 'email' => 'holly@scotch.io', 'password' => Hash::make('secret')],

['name' => 'Adnan Kukic', 'email' => 'adnan@scotch.io', 'password' => Hash::make('secret')],

);

// Loop through each user above and create the record for them in the database

foreach ($users as $user)

{

User::create($user);

}

Model::reguard();

}

}

当我试图运行播种命令php artisan db:seed我收到以下错误.

[ReflectionException]

Class UsersTableSeeder does not exist

谁能在这方面帮助我?

解决方法:

当我在新项目或现有项目中添加播种器时,我已经尝试过这个问题,我想在其中添加一些数据进行测试.

jedrzej.kurylo和Alex都在正确的轨道上,composer dump-autoload将重新生成你的自动加载文件并包含你刚​​添加的播种机.

标签:php,laravel-5-1

来源: https://codeday.me/bug/20190702/1357150.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值