lundi 8 avril 2019

Append data from another model in a model (laravel 5.4)

I want to append the count of data from a table in my database but I am having a problem with the relationship.

I have 3 Models

Voucher model:

vouchers table

VoucherSerial Model:

voucher_serials table

Each voucher will have many serials

UserVoucher Model:

user_vouchers table

When the user redeemed the voucher it will be stored in user_vouchers table. I also had defined the relationship for all the Models

In Voucher.php I want to append the count of the voucher redeemed by the user.

 public function  getVoucherRedeemedAttribute()
{         
   //query to append the voucher redeemed count for each voucher
}

I've tried so many solution but mostly I got errors. My biggest problem is because to count the voucher redeemed for each voucher based on user_vouches table but each voucher has many serial_id which i want to count as the same voucher

I know my explanation regarding the question is bad but I need some help regarding this. Hope someone can help me.

Thank you so much in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire