AdvertiseController.phpLaravelのsave()はすべてのフィールドを保存しません
class AdvertiseController extends Controller
{
...
public function NewAdvertiser()
{
$advertiser = new Advertiser((string)Uuid::generate(4));
$advertiser->createAdvertiser();
return Redirect::route('dashboard');
}
...
}
Advertiser.php
class Advertiser extends Model
{
...
protected $fillable = ['token'];
private $token;
function __construct($token)
{
$this->token = $token;
}
function createAdvertiser()
{
//dd($this);
$this->save();
//dd($this);
}
...
}
最初dd($this)
次のように出力されます
Advertiser {#181 ▼
#fillable: array:1 [▼
0 => "token"
]
-token: "44f1e74b-ad19-4e73-ac2e-b37ffde59e99"
#connection: null
#table: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: []
#original: []
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▼
0 => "*"
]
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: false
+wasRecentlyCreated: false
}
二dd($this)
:
Advertiser {#181 ▼
#fillable: array:1 [▼
0 => "token"
]
-token: "295764d5-c45c-4aa9-8ce2-8ed772687fb8"
#connection: null
#table: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:3 [▼
"updated_at" => "2016-05-19 11:39:42"
"created_at" => "2016-05-19 11:39:42"
"id" => 7
]
#original: array:3 [▼
"updated_at" => "2016-05-19 11:39:42"
"created_at" => "2016-05-19 11:39:42"
"id" => 7
]
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▼
0 => "*"
]
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: true
}
token
にはマイナス記号がありますが、それは何か関係はありますか?私はそれに関する情報を見つけることができませんでした。フィールドの
データベースの移行:
$table->uuid('token');
問題は、すべてのレコードが正常に保存されているということですが、token
フィールドは空白になっています。