gsk
gsk

Reputation: 2379

save many to many relation in Laravel elequent 5?

I have three table,employees,allowances and emp_allowances

In employees

In allowances

In emp_allowances

Model functions are, Employee

  public function empAllowances() {
    return $this->belongsToMany('App\Model\EmplAllowance', 'emp_allowances', 'employees_id', 'allowances_id');
}

Allowance

 public function employees() {
    return $this->belongsToMany('App\Model\Employee');
}

It is working here $emp->empAllowances()->sync([1]); but when I am following this method,I can not save amount.

How can I save employee allowance details with amount?

Upvotes: 2

Views: 115

Answers (1)

pinkal vansia
pinkal vansia

Reputation: 10300

try

$emp->empAllowances()->sync([1 => ['amount' => 10]])

Search for Adding Pivot Data When Syncing here

Upvotes: 2

Related Questions