2つの異なるテーブルにデータを保存しようとしていますが、選択(x-editable)によって異なります。ここに私のコードがあり、私が間違っているところを指し示して助けてくれます。私が探していますlaravelで同時に2つのテーブルにデータを保存する
結果は:製品は、有料の値もTBLに1に0を変更します:私はTBLに支払わに保留中の支払い状況を変更Product_payment
TBL:製品
- product_id
- client_id
...
- status {paid/pending}
TBL:Product_payment
- product_id
- payment_id
....
- paid {1/0}
コントロールLER:
public function update()
{
$inputs = Input::all();
if ($row = Product::with('payments')->find($inputs['pk']))
{
$row->$inputs['name'] = $inputs['value'];
if($row['status'] == 'paid') {
$row['paid'] = 1;
}
$row->save();
return $row;
}
Product.php(モデル)
class Product extends Eloquent
{
protected $primaryKey = 'product_id';
protected $table = 'products';
protected $fillable = array('client_id', 'date', 'amount', 'status', 'notes');
public function payments()
{
return $this->hasMany('ProductPayment');
}
}
ProductPayment.php(モデル)
class ProductPayment extends Eloquent
{
public $table = 'product_payments';
protected $primaryKey = 'product_payment_id';
protected $fillable = array('product_id', 'client_id', 'payment_method', 'amount_paid', 'paid');
public function product()
{
return $this->belongsTo('Products');
}
public function clients()
{
return $this->belongsTo('Clients');
}
}
誰でも、私の質問が答えが不明な場合は教えてください。 – mkrahamath