Jay Gorio
Jay Gorio

Reputation: 335

Cannot display values when editing form in laravel 5

There is no output in the form when clicking a value. But I can see the values when using the return function. Here is my code:

ReportController

      public function edit($id)
{
    $crime_edit = CrimeReport::findOrFail($id);
    $victim_info = VictimProfile::findOrFail($id);
    return $victim_info;
    //return $victim_info->firstname;
    //return $victim_info;
    $display_crime_type = CrimeType::lists('crime_type','id');
    $display_crime_name = CrimeName::lists('crime_description','id');
    return view('crimereports.edit',compact('crime_edit','victim_info','display_crime_name,'display_crime_type'));
}

edit view page

{!! Form::model($crime_edit,['method' =>'PATCH','route'=>'crime_reports.update',$crime_edit->id],'class'=>'form-horizontal']) !!}

          <div class="form-group">
               {!! Form::label('victim_name', 'Victim Name',['class'=>'col-md-3 control-label']) !!}
          <div class="col-md-3">
               {!! Form::text('victim_name', null, ['class' => 'form-control','placeholder' => 'Firstname']) !!}      
          </div>
          <div class="col-md-2">
               {!! Form::text('v_middle_name', null, ['class' => 'form-control','placeholder' => 'Middlename']) !!}      
          </div>
          <div class="col-md-3">
             {!! Form::text('v_last_name', null, ['class' => 'form-control','placeholder' => 'Last Name']) !!} 
        </div>
        </div>
{!! Form::close() !!} 

Am I missing something?

Upvotes: 0

Views: 622

Answers (2)

Trip
Trip

Reputation: 2016

Based on your debug output statements ("return $victim_info;"), it looks like you are trying to bind the form to the $crime_edit model while accessing the values from the $victim_info model. You can not bind a form to two different models at once, so if the blank victim name fields are not attributes of the $crime_edit model, your current implementation will not work.

You will need to either explicitly add $victim_info->victim_name, etc. in place of the 'null' values, or bind the form to the $victim_info model instead of the $crime_edit model.

If victim_name, v_middle_name, and v_last_name are attributes of the $crime_edit model, then I have no idea.

Upvotes: 1

dotty
dotty

Reputation: 41463

The null is the default value. I think Form::model is suppose to bind the values, but have you tried removing the null?

I don't use Form::model, but as a default value I always put old('field_name', $model->field_name). The old function will look into both GET and POST and if a key matches that'll be shown. If that doesn't exist, it'll use the second value.

Upvotes: 1

Related Questions