嘗試將模型綁定到表單以調用更新函數,但未找到模型。Laravel 4 - ErrorException未定義變量
{{ Form::model($upload, array('url' => array('uploads/update', $upload->id), 'files' => true, 'method' => 'PATCH')) }}
控制器來獲取編輯觀點
public function getEdit($id)
{
$upload = $this->upload->find($id);
if (is_null($upload))
{
return Redirect::to('uploads/alluploads');
}
$this->layout->content = View::make('uploads.edit', compact('uploads'));
}
控制器做更新
public function patchUpdate($id)
{
$input = array_except(Input::all(), '_method');
$v = Validator::make($input, Upload::$rules);
if ($v->passes())
{
$upload = $this->upload->find($id);
$upload->update($input);
return Redirect::to('uploads/show', $id);
}
return Redirect::to('uploads/edit', $id)
->withInput()
->withErrors($v)
}
錯誤,我得到
ErrorException
Undefined variable: upload (View: /www/authtest/app/views/uploads/edit.blade.php)
你的約束力在哪裏?你是否在路線上綁定模型? –
在路由中,我有Route :: controller('uploads','UploadsController'); – cch
然後,您必須在加載/顯示錶單時從控制器傳遞模型,如何顯示錶單,代碼? –