I cannot figure out why im not allowed to insert a null or empty while SQL default is set
got this error Integrity constraint violation: 1048 Column 'comment' cannot be null
my migration is
$table->integer('user_id')->unsigned();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade')
->onUpdate('cascade');
$table->string('verse');
$table->text('content');
$table->string('comment',512)->default('No Tag');
and my controller is
$post = (object) $request->all();
$favorite = new FavoriteVerse($request->all());
$favorite->getUser()->associate($this->user);
$favorite->save();
and my form is
{{csrf_field()}}
<input type='hidden' id='modalInputFullReference' name='verse' value=''/>
<input type='hidden' id='modalInputContent' name='content' value=''/>
<div class='box-body'>
<div class='form-group'>
<label>Tag, about this verse</label>
<input class="form-control" placeholder='Ex. a,b,c' name='comment' type="text" />
</div>
</div>
any thought is appreciated thankyou
try this in migration file
$table->string('comment',512)->default('No Tag')->nullable();
its value would always be null instead of the default value
nullable() allows the attribute to be null, with default() the attribute will take the default value instead of null
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community