Reputation: 553
Migration
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePlayersTable extends Migration
{
public function up()
{
Schema::create('players', function (Blueprint $table) {
$table->increments('id');
$table->string('username');
$table->boolean('status')->default(1); // True
$table->timestamps();
$table->softDeletes();
});
}
public function down()
{
Schema::drop('players');
}
}
Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Player extends Model
{
use SoftDeletes;
protected $table = 'players';
protected $fillable = ['id', 'username', 'status'];
protected $dates = ['deleted_at'];
}
Seeder
<?php
use Illuminate\Database\Seeder;
use Carbon\Carbon as Carbon;
class PlayersSeeder extends Seeder
{
public function run()
{
DB::table('players')->insert([
[
'id' => 1,
'username' => 'EKBD0223',
'status' => 0,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
'deleted_at' => NULL,
]
]);
}
}
Why is it when run php artisan db:seed
it doesn't throw an error but when i check the database, the data from the seeder doesn't insert at the table?
Is there i miss out? because i don't see error in my code :(
Upvotes: 1
Views: 839
Reputation: 2483
You have to add the seeder to the main seeder: DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(PlayersSeeder::class);
}
}
Upvotes: 4