【发布时间】:2015-08-26 18:25:47
【问题描述】:
所以我在迁移数据库后尝试使用基本的php artisan db:seed,但它在 cmd -[Symfony\Component\Debug\Exception\FatalErrorException] Class 'User' not found 中不断返回标题错误
我尝试过的事情
- 更新类后的 php dump-autoload
- 运行
db:seed函数之前的php dump-autoload - 回滚迁移,然后重新运行它
- 回滚迁移,然后使用
--seed语法重新运行它 - 更改“用户”文件的命名空间
以下是迁移
<?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');
}
}
我相信这里的一切都是正确的,现在这里是用户类。
<?php namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
}
现在最后是最重要的数据库播种器
<?php
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('UserTableSeeder');
$this->call('UserTableSeeder');
Model::reguard();
}
}
class UserTableSeeder extends Seeder
{
public function run()
{
DB::table('users')->delete();
User::create(['email' => 'John@doe.com']);
}
}
这就是我的完整语法,如果需要更多文件,请请求它们,我会更新我的问题。
【问题讨论】:
标签: php laravel-5 laravel-artisan