1

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');
  }

}
4

2 に答える 2

1

あなた$productはそれにデータを持っていると確信していますか?

Route::get('/test', function() {

    $user = new User;
    $user->email = 'me@mydomain.com';
    return View::make('test', compact('user'));

});

ビュー (test.blade.php):

{{ Form::model($user, array(
  'method' => 'PATCH', 
)) }}
{{ Form::label('email', 'E-mail:') }}
{{ Form::text('email') }} <!-- here's da thing! -->
{{ Form::submit('Update', array('class' => 'btn btn-info')) }}
{{ Form::close() }}

結果:

ここに画像の説明を入力

于 2013-10-24T12:19:44.943 に答える