php - Laravel - Query just one row in a pivot table and return all data within the relationship -


currently, criteria belongstomany alerts , viceversa. related through pivot table: criteria_id , alert_id.

i getting criteria associated alerts belongs authenticated user, such:

public function getmatches()     {         $matches = criteria::whereuserid( auth::id() )         ->has('alerts')         ->get();      } 

this returns associated results, whereas now, if user picks result, want able show that. have far:

controller

public function getmatchdetails($alert_id, $criteria_id) {      $matches = alert::find($alert_id)     ->has('criterias')     ->where('criteria_id', $criteria_id)     ->get();  } 

which bringing on correct variables, however, getting mysql error:

column not found: 1054 unknown column 'criteria_id' in 'where clause'

select * `alerts` `alerts`.`deleted_at` null ,  (select count(*) `criterias` inner join `alert_criteria` on `criterias`.`id` = `alert_criteria`.`criteria_id` `alert_criteria`.`alert_id` = `alerts`.`id`) >= 1 , `criteria_id` = 7) 

screenshot

any hugely appreciated.

you try this

public function getmatchdetails($alert_id, $criteria_id) {      $match = alert::wherehas('criterias', function ($q) use ($criteria_id) {         $q->where('criteria_id', $criteria_id);     })->find($alert_id);  } 

which find alert id , check has relationship criterias meeting requirements.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -