Laravel DatabaseSeeding -
i'm trying learn laravel. i'm not busy seeding put keep getting following error:
[reflectionexception] class usertableseeder not exist
what have done:
user class
use illuminate\auth\authenticatable; use illuminate\database\eloquent\model; use illuminate\auth\passwords\canresetpassword; use illuminate\contracts\auth\authenticatable authenticatablecontract; use illuminate\contracts\auth\canresetpassword canresetpasswordcontract; class user extends model implements authenticatablecontract, canresetpasswordcontract { use authenticatable, canresetpassword; /** * database table used model. * * @var string */ protected $table = 'users'; /** * attributes mass assignable. * * @var array */ protected $fillable = ['name', 'username', 'email', 'password']; /** * attributes excluded model's json form. * * @var array */ protected $hidden = ['password', 'remember_token']; }
createusertable migration:
use illuminate\database\schema\blueprint; use illuminate\database\migrations\migration; class createuserstable extends migration { /** * run migrations. * * @return void */ public function up() { schema::create('users', function (blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('username'); $table->string('email')->unique(); $table->string('password', 60); $table->remembertoken(); $table->timestamps(); }); } /** * reverse migrations. * * @return void */ public function down() { schema::drop('users'); } }
usertableseeder
use illuminate\database\seeder; use illuminate\database\eloquent\model; class usertableseeder extends seeder { /** * run database seeds. * * @return void */ public function run() { db:table('users')->delete(); user::create(array( 'name' => 'graham neal', 'username' => 'graham', 'email' => 'grahamneal1991@gmail.com', 'password' => hash::make('0258456'), )); } }
databaseseeder
use illuminate\database\seeder; use illuminate\database\eloquent\model; class databaseseeder extends seeder { /** * run database seeds. * * @return void */ public function run() { model::unguard(); // $this->call(usertableseeder::class); $this->call('usertableseeder'); model::reguard(); } }
in database seeder i've tried following:
$this->call('usertableseeder'); $this->call('usertableseeder::user'); $this->call('app/usertableseeder'); $this->call('app/usertableseeder::user');
i know can't find class left in dark finding out why? i've searched google , found other places went wrong other people don't seem have same mistakes. hope isn't stupid question.
edit*
if composer dump-autoload above error , following exception trace:
[runtimeexception] not scan classes inside "user" not appear file nor folder
this error given after added class manually composer.json file.
now if i'm trying php artisan db:seed error:
[symfony\component\debug\exception\fatalerrorexception] call undefined function table()
first, make sure seeder in database/seed/ directory.
then, use composer's dump-autoload
Comments
Post a Comment