在laravel中编辑表单时,我无法查看表单上传递的值。当我输入值时,它成功添加到表中。但是,当我想编辑值时,它们是不可见的。但是,当我在输入表单之外调用值时,我可以查看该值。
请参阅下面的代码。有人可以帮助我。谢谢。
create.blade.php
<div class="panel-heading">
<h3 class="panel-title">New Report Form</h3>
</div>
<div class="panel-body">
@include('errors.list')
@include('partials.success')
{!! Form::open(['route'=>'crime_reports.store','class'=>'form-horizontal']) !!}
@include('crimereports._form')
<div class="form-group">
<div class="col-md-7 col-md-offset-3">
{!! Form::submit('Save Changes', ['class'=>'btn btn-primary btn-md']) !!}
<i class="fa fa-save"></i>
</div>
</div>
{!! Form::close() !!}
</div>
<div class="panel-footer ">
<p><small>Crime Chase</small></p>
</div>
edit.php
{!! Form::model('$crime_edit',['method' => 'PATCH','route'=>['crime_reports.update',$crime_edit->id],
'class'=>'form-horizontal']) !!}
@include('crimereports._form')
<div class="form-group">
<div class="col-md-7 col-md-offset-3">
{!! Form::submit('Update Form', ['class'=>'btn btn-primary btn-md']) !!}
</div>
</div>
{!! Form::close() !!}
</div>
<div class="panel-footer ">
<p><small>Crime Chase</small></p>
</div>
crimereportcontroller
public function store(CrimeNewReportRequest $request)
{
$input = $request->all();
CrimeReport::create($input);
// $input = CrimeReport::create($request->all());
// return redirect('crime_reports')->withSuccess("Fields were inserted!");
return redirect()->back();
}
public function edit($id)
{
$crime_edit = CrimeReport::findOrFail($id);
return view('crimereports.edit',compact('crime_edit',$crime_edit));
}
_form
<div class="form-group">
{!! Form::label('crime_victim', 'Victim Name',['class'=>'col-md-3 control- label']) !!}
<div class="col-md-8">
{!! Form::text('crime_victim', null, ['class' => 'form-control',
'placeholder' => 'Enter Victim name']) !!}
</div>
<div class="form-group">
{!! Form::label('crime_suspect', 'Suspect Name',['class'=>'col-md-3 control-label']) !!}
<div class="col-md-8">
{!! Form::text('crime_suspect', null, ['class' => 'form-control',
'placeholder' => 'Enter Suspect Name']) !!}
</div>
<div class="form-group">
{!! Form::label('suspect_description','List Description' ,['class'=>'col-md-3 control-label']) !!}
<div class="col-md-8">
{!! Form::textarea('suspect_description', null, ['class'=>'form-control',
'placeholder'=>'Details about suspect']) !!}
</div>
答案 0 :(得分:1)
使用表单模型绑定时,应该将模型作为参数传递。你很亲密您拥有$crime_edit
模型,但出于某种原因,您将其作为字符串传递。
更改此
{!! Form::model('$crime_edit',
这应该可以解决你的问题:
{!! Form::model($crime_edit,