事情是关于输入字段和使用Form::model()
绑定检索相关数据。我怎样才能做到这一点?文本输入的绑定结果为空qty
。我正在考虑从模型中进行黑客攻击...可能从model()
?
表单(app/views/products/edit.blade.php)
{{ Form::model($product, array(
'method' => 'PATCH',
'route' => array('products.update', $product->id),
'class' => 'form-inline'
)) }}
{{ Form::label('name', 'Name:') }}
{{ Form::text('name') }}
{{ Form::label('qty', 'Price:') }}
{{ Form::text('qty') }} <!-- here's da thing! -->
{{ Form::submit('Update', array('class' => 'btn btn-info')) }}
{{ Form::close() }}
应用程序/控制器/ProductsController.php
class ProductsController extends BaseController {
public function edit($id) {
$product = Product::find($id);
if (is_null($product)) return Redirect::route('products.index');
return View::make('products.edit', compact('product'));
}
}
应用程序/模型/
class Product extends Eloquent {
public $timestamps = false;
protected $fillable = array('name');
public function prices() {
return $this->hasMany('Price');
}
public function images() {
return $this->morphMany('Image', 'imageable');
}
}
class Price extends Eloquent {
protected $table = 'product_prices';
public $timestamps = true;
protected $fillable = array('qty');
public static $rules = array(
'qty' => 'required|numeric'
);
public function product() {
return $this->belongsTo('Product');
}
}