Laravel - Sum of pivot table results given a criteria -


Scenarios There may be several warnings in a warning, and many alerts may be my alerts .

A user has been assigned a criteria. When a user sees all their criteria , I want to see the sum of how many matching alerts (stored in pivot tables). Relationships Structured Using a Pivot Table:

screenshot

For example, I can access the warning and criteria data and also let me know that for criteria_id = 73 , there is a warning match id_2 .

then present

formula:

  public function getIndex () {$ alerts = criteria :: with ('coordinate', ' Alerts') - & gt; Where ('user_id', '=', at: :: user () -> ID) - & gt; get (); $ This- & gt; Layout-> Content = View :: Create ('users.alert.index', array ('alerts' => alerts)); }  

Relationship between alert model

  public function criterion () {return $ this- & gt; Affiliation Value ('criteria') - & gt; WithTimestamps (); }  

Relationship between benchmarking model

  public function alert (return) {return $ this- & gt; Related Tommen ('Alert') - & gt; WithTimestamps (); }  

If you need more information, please let me know. Thanks very much for your help.

I resolved my question using the example given above @Jerek Tacaxi.


Comments