Linked Questions

Popular Questions

updated_at column ambigious while updating with eloquent

Asked by At

I have 3 table cart,pharmacy and cart_pharmacies

cart table

cart_id | user_id | total_price | status | created_at | updated_at

pharmacy table

pharmacy_id | name | address_id | created_at | updated_at

cart_pharmacies table

cart_pharmacies_id | cart_id | pharmacy_id | created_at | updated_at

In cart modal i define relation

   public function pharmacy()
        return $this->belongsToMany('App\Pharmacy','cart_pharmacies','cart_id','pharmacy_id');

In parmacy modal i define

public function cart()
    return $this->belongsToMany('App\Cart','cart_pharmacies','pharmacy_id','cart_id');

In controller i have pharmacy_id i am trying to update cart status with code

$pharmacy=  Pharmacy::findOrFail($pharmacy_id);

but it is giving me error

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 
'updated_at' in field list is ambiguous (SQL: update `cart` inner join 
`cart_pharmacies` on `cart`.`cart_id` = `cart_pharmacies`.`cart_id` set 
`status` = 1, 
`updated_at` = 2016-05-31 07:14:47 where `cart_pharmacies`.`pharmacy_id` = 5)

Related Questions