$save=$data->save();if ($save) { Schema::table('users', function($table) { $table->string($data->id); }); return back()->withInput()->with('message','Carrier Created Successfully');}И 在表中保存的數(shù)據(jù)比想在用戶表中添加具有該數(shù)據(jù) ID 的列但出現(xiàn)錯(cuò)誤:未定義變量 $data突出顯示的行是:$table->string($data->id);
2 回答

qq_花開花謝_0
TA貢獻(xiàn)1835條經(jīng)驗(yàn) 獲得超7個(gè)贊
內(nèi)部函數(shù)外的變量在內(nèi)部函數(shù)內(nèi)不可用。為此,您需要使用傳遞變量use
$save=$data->save();
if ($save) {
Schema::table('users', function($table) use ($data) {
$table->string($data->id);
});
return back()->withInput()->with('message','Carrier Created Successfully');
}
現(xiàn)在$data應(yīng)該在函數(shù)內(nèi)部可用。

慕森王
TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊
您需要使用use
從一個(gè)函數(shù)到另一個(gè)函數(shù)的其他變量
Schema::table('users', function($table) use ($data) { $table->string($data->id); });
- 2 回答
- 0 關(guān)注
- 170 瀏覽
添加回答
舉報(bào)
0/150
提交
取消