1
<?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');
}
}
模型
<?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'];
}
播種機
<?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,
]
]);
}
}
爲什麼運行時php artisan db:seed
它不會引發錯誤,但是當我檢查數據庫時,播種機中的數據不會在表中插入? 我有錯過嗎?因爲我沒有看到在我的代碼:(
我看到所以這是一個我忘了感謝! – Jefsama