maudev maudev - 1 year ago 110
HTML Question

Laravel: migration default() field does not work

i having troubles with my migration field default('No description'), i need to save a default value for my null fields on my form, but when i save, my form data stores empty fields.. why? i'm working with Laravel 5.2 and it is my code:

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

My view:

<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 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/>

Answer Source

in your store function do this

$input = $request->all();
$input['description'] = $request->description;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download