此模型行爲不正確。它沒有填寫它的屬性,也不能撥打find()
,get()
或任何類型的吸氣劑。創建和獲取模型的錯誤
這裏是它的create_matches_table:
public function up()
{
Schema::create('matches', function (Blueprint $table) {
$table->increments('id');
$table->integer('p1');
$table->integer('p2');
$table->integer('u1');
$table->integer('u2');
$table->string('p1_action')->nullable();
$table->string('p2_action')->nullable();
$table->bigInteger('clock')->unsigned();
$table->smallinteger('round')->unsigned()->default('1');
$table->integer('victor')->nullable();
$table->boolean('murder');
$table->integer('wager')->unsigned()->nullable();
$table->integer('notoriety')->nullable();
$table->integer('stalemate')->default('0');
$table->timestamps();
$table->datetime('finished_at')->nullable();
});
}
使用Match::create($data)
其中$data
是屬性的數組完美排隊與那些需要將不會填充它們返回的對象從不具有clock
屬性如上述所希望的。
public static function setMatch($data)
{
$match = new Match;
$match->fill($data);
$match->clock = time() + 6;
$match->save();
return $match;
}
即使是在這樣做,試圖讓這個對象由$match = Match::find([$id])->first();
的特定記錄產生這個錯誤:
SQLSTATE[HY000]: General error: 2031 (SQL: select * from
matches
wherematches
.id
in (?)) in Connection.php line 729
at
> Connection->runQueryCallback('select * from `matches` where
> `matches`.`id` in (?)', array(), object(Closure)) in Connection.php
> line 685 at Connection->run('select * from `matches` where
> `matches`.`id` in (?)', array(), object(Closure)) in Connection.php
> line 349 at Connection->select('select * from `matches` where
> `matches`.`id` in (?)', array(), true) in Builder.php line 1610
我已經勉強通過繞行這些問題我嘗試了硬編碼值,將它作爲一個數組傳遞,甚至只是爲了Match::first()
,並且都返回這個錯誤。
所有我需要的是爲此作爲一個常規的醇模型。
你配置你的數據庫設置嗎? –