Laravel 4 seeds successfully returned, but nothing in the database

I am working with Laravel 4 and trying to sow a database with some users. I use the Zizaco Confide plugin, so my User model extends ConfideUser instead of Eloquent for documentation. I added a few fields to the model, but nothing super complicated. I tried to delete these fields, but I have the same problem.

I created a UserSeeder class that I call using DatabaseSeeder and then launched php artisan migrate:refresh --seed . It works without errors and returns "Database sown", and this is true for every table except users . No user is inserted. I tried to create a user with User::create(array(...)) , as well as $user = new User ... $user->save() , and I get the same results. Errors are not reset, and there is nothing in any log that I can find in the system. If I insert some var_dumps into the UserSeeder-> run () method, I see that the objects are created with the correct values, but nothing is saved.

What am I missing? Here are some code examples, I can provide more if necessary:

\ User.php models:

 <?php use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; use Zizaco\Confide\ConfideUser; //class User extends Eloquent implements UserInterface, RemindableInterface { class User extends ConfideUser { // for Entrust use \Zizaco\Entrust\HasRole; /** * The database table used by the model. * * @var string */ protected $table = 'users'; /** * The attributes excluded from the model JSON form. * * @var array */ protected $hidden = array('password'); public function agency() { if ($this->agency_type == 'local') { return $this->hasOne('Local'); } if ($this->agency_type == 'county') { return $this->hasOne('County'); } } /** * Get the unique identifier for the user. * * @return mixed */ public function getAuthIdentifier() { return $this->getKey(); } /** * Get the password for the user. * * @return string */ public function getAuthPassword() { return $this->password; } /** * Get the e-mail address where password reminders are sent. * * @return string */ public function getReminderEmail() { return $this->email; } } 

database \ migration \ xxxxxxxxx_confide_setup_users_table.php:

 <?php use Illuminate\Database\Migrations\Migration; class ConfideSetupUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { // Creates the users table Schema::create('users', function($table) { $table->increments('id'); $table->string('username'); $table->string('email'); $table->string('password'); $table->string('confirmation_code'); $table->boolean('confirmed')->default(false); $table->string('address1'); $table->string('address2')->nullable(); $table->string('state', 2); $table->string('zipcode', 9); $table->string('phone', 10); $table->string('extension',5 )->nullable(); $table->string('fax', 10)->nullable(); $table->enum('agency_type', array('local', 'county', 'state'))->default('local'); $table->integer('agency')->unsigned()->nullable(); $table->dateTime('last_seen'); $table->timestamps(); $table->softDeletes(); }); // Creates password reminders table Schema::create('password_reminders', function($t) { $t->string('email'); $t->string('token'); $t->timestamp('created_at'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('password_reminders'); Schema::drop('users'); } } 

Database \ seeds \ UserSeeder.php:

 <?php use \Illuminate\Database\Seeder; class UserSeeder extends Seeder { public function run() { DB::table('users')->delete(); User::create( array( 'username' => 'local_test', 'email' => ' nathan@abc.com ', 'password' => Hash::make('local'), 'confirmation_code' => '483JU3ID8', 'confirmed' => true, 'address1' => '123 Main St.', 'state' => 'MI', 'zipcode' => '12345', 'phone' => '5559993436', 'agency_type' => 'local', 'agency' => null, 'last_seen' => new DateTime ) ); 
+6
source share
3 answers

Do this in your user seeder class:

 class UsersTableSeeder extends Seeder { public function run() { DB::table('users')->truncate(); $users = array( array( 'username' => 'local_test', 'email' => ' nathan@abc.com ', 'password' => Hash::make('local'), 'confirmation_code' => '483JU3ID8', 'confirmed' => true, 'address1' => '123 Main St.', 'state' => 'MI', 'zipcode' => '12345', 'phone' => '5559993436', 'agency_type' => 'local', 'agency' => null, 'last_seen' => new DateTime ) ); // make sure you do the insert DB::table('users')->insert($users); } } 

and then make sure you call it in the DatabaseSeeder.php file

 <?php class DatabaseSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { $this->call('UsersTableSeeder'); } } 
+3
source

Confide uses Ardent to verify. adding the password_confirmation property. You also don't need Hash :: make, as Confide will also handle this for you.

 <?php class UsersTableSeeder extends Seeder { public function run() { DB::table('users')->truncate(); $users = array( array( 'username' => 'local_test', 'email' => ' nathan@abc.com ', 'password' => 'local', 'password_confirmation' => 'local', 'confirmation_code' => '483JU3ID8', 'confirmed' => true, 'address1' => '123 Main St.', 'state' => 'MI', 'zipcode' => '12345', 'phone' => '5559993436', 'agency_type' => 'local', 'agency' => null, 'last_seen' => new DateTime ) ); // make sure you do the insert DB::table('users')->insert($users); } } 
+1
source

I found that the seeder is failing.

I saw a user table. The return was the success of the seed, but it was empty. I followed the answer above using the insert method. An error was returned while executing the above method, indicating that the column has no default value in the database table.

I adjusted the column and returned to the create method from the laravel document. It was a success.

So, in my case there was a database error, but it failed without telling me. With the insert method, I managed to find an error. Then the create method worked when there were no errors.

0
source

Source: https://habr.com/ru/post/956183/


All Articles