[英]Laravel Edit form error
這是我的表格:
{!! 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);
表格中出現Undefined variable: countries
的問題是什么Undefined variable: countries
刀片出現Undefined variable: countries
錯誤?
從我們在評論中的對話中鞏固這個答案。
錯誤Undefined variable: countries
刀片視圖(窗體)中的國家/地區出現,因為您忘記了將所述變量傳遞給視圖。
在edit
函數(因此該函數調用視圖)中,添加以下內容
$countries = Country::find($id); // though I'd suggest naming it $country
...
return view('<view_name>', compact('countries'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.