本文介紹了Laravel 4 IlluminateDatabaseEloquentMassAssignmentException 錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
嘿,我已經在那里搜索了很多答案,但無法解決這個問題.
Hei, I already searched many answers out there but could not solve this problem.
這是我的遷移代碼
<?php
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
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();
}
我正在像這樣調用激活表.
And i am calling Activation table like this.
Activation::create(['id' => 2, 'token' => 1231]);
說真的,我不知道這里出了什么問題.我是 Laravel 4 的新手.希望有人教我發生了什么以及如何解決它.
Seriously i have no idea what's wrong here. And i am newbie at laravel 4. Hope somebody with teach me whats happening and how to solve it.
推薦答案
當您使用 Activation 類中使用 $fillable
屬性"http://laravel.com/docs/eloquent#mass-assignment">批量賦值.
You need to use the $fillable
property in your Activation
class when you use Mass Assignment.
class Activation extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'activations';
protected $fillable = ['id', 'token'];
}
這篇關于Laravel 4 IlluminateDatabaseEloquentMassAssignmentException 錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!