vendredi 31 mai 2019

How to fetch all from table1 and attach count of rows from table2 in a single query by laravel eloquent

I'm using Laravel 5.8, and I have 2 tables in a (one-to-many) relationship as below:

Contacts DB

  • id
  • name
  • number

Send DB

  • id
  • user_id
  • text
  • to
  • time

what I want to achieve is a list of all (Contacts) along with how many (send) they've made that related to that (contact) by matching Contacts.id with Send.user_id,

here is the result of the query that I'm looking for:

Query result:

  • id
  • name
  • number
  • count of Sends

Thank you :)



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2WgeCkZ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire