這是我的原始表格,稱為問題:
public function up()
{
Schema::create('questions', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug');
$table->string('image')->nullable();
$table->string('audio')->nullable();
$table->string('type');
$table->unsignedBigInteger('evaluation_id');
$table->foreign('evaluation_id')->references('id')->on('evaluations')->onDelete('cascade');
$table->timestamps();
});
}
使用這段代碼,我在現有表中添加了一個新列:
php artisan make:migration add_rule_to_questions_table --table=questions
php artisan migrate
在新列的遷移檔案中,在 up() 方法中添加了這個:
public function up()
{
Schema::table('questions', function (Blueprint $table) {
$table->longText('rule')->nullable();
});
}
至此,新列成功添加到資料庫中。但是,當我嘗試將資料添加到“問題”表的新列時,資料不會保存在資料庫中。
在創建表單中,我使用以下代碼:
<div class="form-group">
<label>Rules:</label>
<textarea name="rule" id="rule" class="form-control" value="{{old('rule')}}"></textarea>
@error('rule')
<small class="text-danger">{{$message}}</small>
@enderror
</div>
最后在控制器的存盤方法()中,我使用以下代碼保存資料:
public function store(Request $request){
Question::create([
'title' => $request->title,
'slug' => $request->slug,
'evaluation_id' => $request->evaluation_id,
'type' => "OM",
'rules' => $request->rule,
]);
}
但是新列沒有保存資料,可能是什么錯誤?
uj5u.com熱心網友回復:
您需要添加到模型中的rules陣列$fillableQuestion
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/532794.html
上一篇:升級節點后的Webpack錯誤:“模塊決議失敗:意外令牌”
下一篇:CakePhp4的可疑快取問題
