以下是我迁移的代码
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateActiveTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('activations', function($table)
{
$table->bigInteger('id')->primary();
$table->tinyInteger('token');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('activations');
}
}
对于型号( models / Activation.php )
<?php
class Activation extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'activations';
protected $guarded = array();
}
我正在调用这样的激活表。
Activation::create(['id' => 2, 'token' => 1231]);
说真的,我不知道这里有什么问题。我是laravel 4的新手。希望有人教我发生什么,以及如何解决它。
答案 0 :(得分:22)
使用Mass Assignment时,您需要使用$fillable
课程中的Activation
媒体资源。
class Activation extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'activations';
protected $fillable = ['id', 'token'];
}