0

我正在制作一个表格来编辑数据库中的现有条目。我正在使用 Form::model 方法来执行此操作,但是它似乎不起作用。字段只是保持空白。

服务器控制器.php

/**
* Editing servers
*/
public function edit($name)
{
  $server = Server::find($name);
  $keywords = ($server->getKeywords()) ? $server->getKeywords() : array();
  $countries = $this->getCountries();
  return View::make('server/edit', array('server' => $server, 'countries' => $countries));
}

public function update($name) 
{
  $server = Server::find($name);
  // Did it succeed?
  if($server->save()) {
    Session::flash('success', 'You server was edited!');
    return Redirect::route('server.view', array($name));
  }

  // Did not validate
  if(Input::get('keywords')) {
    $keywords = Input::get('keywords');
    Session::flash('keywords', $keywords);
  }
  Session::flash('danger', "<b>Oops! There were some problems processing your update</b><br/>" . implode("<br/>", $server->errors()->all()));
  return Redirect::route('server.edit', array($name))->withInput()->withErrors($server->errors());
}

表格

{{ Form::model($server, array('route' => array('server.update', $server->name), 'class' => 'form-horizontal', 'role' => 'form', 'files' => true)) }}
  <div class="form-group {{ $errors->has('email') ? 'has-error' : '' }}">
    {{ Form::label('email', 'Email', array('class' => 'control-label col-md-4')) }}
    <div class="col-md-4">
      {{ Form::text('email', '', array('class' => 'form-control')) }}
      {{ $errors->first('email', '<br/><div class="alert alert-danger">:message</div>') }}
    </div>
  </div>
  (some more fields)
{{ Form::close() }}
4

1 回答 1

7

这里的问题是您传入一个空字符串作为默认字段值。正如这里的文档所述,任何显式传递的值都将推翻模型属性数据。尝试使用null而不是''

{{ Form::text('email', null, array('class' => 'form-control')) }}
于 2014-03-19T22:09:47.933 回答