2014-03-30 16 views
8

Hei, ich habe schon viele Antworten gesucht, aber konnte dieses Problem nicht lösen. HierLaravel 4 Illuminate Datenbank Eloquent MassAssignmentException Fehler

ist der Code für meine Migration

<?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'); 
    } 
} 

Für Modell (Modelle/Activation.php)

<?php 

class Activation extends Eloquent { 

    /** 
    * The database table used by the model. 
    * 
    * @var string 
    */ 
    protected $table = 'activations'; 
    protected $guarded = array(); 
} 

Und ich rufe Aktivierungs Tabelle wie folgt.

Activation::create(['id' => 2, 'token' => 1231]); 

Ernsthaft habe ich keine Ahnung, was hier falsch ist. Und ich bin ein Neuling bei Laravel 4. Hoffe, dass jemand mir beibringt, was passiert und wie man es löst.

+0

Mögliche Duplikat [MassAssignmentException in Laravel] (http://stackoverflow.com/questions/22280136/massassignmentexception-in-laravel) –

Antwort

22

Sie müssen die $fillable Eigenschaft in Ihrer Activation Klasse verwenden, wenn Sie Mass Assignment verwenden.

class Activation extends Eloquent { 

    /** 
    * The database table used by the model. 
    * 
    * @var string 
    */ 
    protected $table = 'activations'; 

    protected $fillable = ['id', 'token']; 
} 
+0

Noch gleichen Fehler – user3478596

+0

Versuchen $ bewacht Linie zu entfernen. Möchten Sie ID wirklich manuell zuweisen? – user2094178

+0

Gibt es einen Grund, eine automatisch inkrementierte ID zu erstellen? während alles, was ich brauche, ist eine ID von mir selbst eingeben, habe ich versucht – user3478596

Verwandte Themen