这是我的表格:
(,)
这是我的更新功能:
{!! Form::model($countries, ['route' => ['countries.update', $countries->id], 'method' => "PUT"]) !!}
{{ Form::label('code', 'Country Code:') }}
{{ Form::text('code', null, ['class' => 'form-control']) }}
{{ Form::label('name', 'Country Name:') }}
{{ Form::text('name', null, ['class' => 'form-control']) }}
{{ Form::submit('Save', ['class' => 'mt-20 btn btn-success btn-sm']) }}
{!! Form::close() !!}
我的表单中的问题是什么,我的刀片出现$countries = Country::find($id);
$this->validate($request, array(
'code' => 'required|min:2|max:4',
'name' => 'required|max:255'
));
$country = Country::where('id',$id)->first();
$country->code = Input::get('code');
$country->name = Input::get('name');
$country->save();
Session::flash('success', 'The Country info was successfully updated.');
return redirect()->route('locations.index', $country->id);
错误?
答案 0 :(得分:3)
在评论中巩固我们对话中的答案。
由于您忘记将所述变量传递给视图,因此会出现刀片视图(窗体)中的错误Undefined variable: countries
。
在edit
函数中(因为这是调用视图的函数),添加以下
$countries = Country::find($id); // though I'd suggest naming it $country
...
return view('<view_name>', compact('countries'));