Laravel:迁移default()字段不起作用

毛德夫

我在迁移字段default('No description')时遇到麻烦,我需要在表单上保存空字段的默认值,但是当我保存时,表单数据存储空字段..为什么呢?我正在使用Laravel 5.2,这是我的代码:

    public function up()
{
    Schema::create('combos', function (Blueprint $table) {
        $table->increments('id');
        $table->string('item_name');
        $table->string('description')->nullable()->default('No description');
        $table->decimal('price', 5, 2);
        $table->decimal('buy_price', 5, 2);   
        $table->timestamps();
    });
}

我的看法:

    <div class="form-group">
    {!! Form::label('item_name','Item: ',['class'=>'control-label col-md-2']) !!}
    <div class="col-md-7" >
        {!! Form::text('item_name',null,['class'=>'form-control','placeholder'=>'Enter a item name','required','min'=>5]) !!}<br/>
    </div>
</div>
<div class="form-group">
    {!! Form::label('price','Price: ',['class'=>'control-label col-md-2']) !!}
    <div class="col-md-7" >
        {!! Form::text('buy_price',null,['class'=>'form-control','placeholder'=>'Enter a price','required']) !!}<br/>
    </div>
</div>
哈梅拉杰

在您的商店功能中执行此操作

$input = $request->all();
$input['description'] = $request->description;
Combos::create($input);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章