save many to many relation in Laravel elequent 5?

gsk

I have three table,employees,allowances and emp_allowances

In employees

  • id
  • name

In allowances

  • id
  • title
  • amount

In emp_allowances

  • employees_id
  • allowances_id
  • amount

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?

pinkal vansia

try

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

Search for Adding Pivot Data When Syncing here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

save many to many relation in Laravel elequent 5?

From Dev

Laravel Many to Many relation

From Dev

Laravel 5 - Many to Many - Attach versus Save

From Dev

laravel 5.1 many to many relation

From Dev

Laravel Many-to-Many Relation

From Dev

Search in many to many relation Laravel

From Dev

Laravel many relation insert

From Dev

Laravel one to many relation

From Dev

Is it possible to save one to many relation in one line Laravel eloquent

From Dev

Laravel ORM many to many relation with conditions on keys

From Dev

Laravel get data from many to many relation

From Dev

Laravel: ordering a many-many relation

From Dev

Laravel - Many to Many Polymorphic Relation with Extra Fields

From Dev

Laravel Repository pattern and many to many relation

From Dev

laravel Many To Many relationship with inner relation

From Dev

Laravel 5 Eloquent relation "Has Many Through" SQL Exception

From Dev

Laravel Has Many Through relation

From Dev

laravel 5.1 getting related 5 news of each category in many-to-many relation

From Dev

Laravel 5 – get particular many to many relation based on model and related model ID

From Dev

How to save embeds_many relation in Mongoid?

From Dev

How to save 1 to many relation with Bookshelfjs

From Dev

RubyonRails Not able to save has_many relation

From Java

Laravel save / update many to many relationship

From Dev

Laravel 5 Eloquent ORM - Many to Many through Many to Many

From Dev

Many to Many Eloquent Relation

From Dev

Working with Many to Many relation

From Dev

Select for many to many relation

From Dev

Select on many to many relation

From Dev

Laravel save one to many relationship

Related Related

HotTag

Archive