The problem remains that new column added to existing table in Laravel 9 is not saving data
P粉262073176
P粉262073176 2023-08-30 13:15:31
0
1
512
<p>Here is my original form, called questions:</p> <pre class="brush:php;toolbar:false;">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(); }); }</pre> <p>Using this code, I added a new column to an existing table: </p> <pre class="brush:php;toolbar:false;">php artisan make:migration add_rule_to_questions_table --table=questions php artisan migrate</pre> <p>In the migration file for the new column, the following was added in the up() method: </p> <pre class="brush:php;toolbar:false;">public function up() { Schema::table('questions', function (Blueprint $table) { $table->longText('rule')->nullable(); }); }</pre> <p>At this point, the new column has been successfully added to the database. However, when I try to add data to a new column of the "Problems" table, the data is not saved in the database. </p> <p>In creating the form I use the following code: </p> <pre class="brush:php;toolbar:false;"><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></pre> <p>Finally in the controller's store method() I save the data using the following code: </p> <pre class="brush:php;toolbar:false;">public function store(Request $request){ Question::create([ 'title' => $request->title, 'slug' => $request->slug, 'evaluation_id' => $request->evaluation_id, 'type' => "OM", 'rules' => $request->rule, ]); }</pre> <p>But the new column does not save data. What could be the error? </p>
P粉262073176
P粉262073176

reply all(1)
P粉738046172

You need to add rules to the Question array in your model $fillable

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!