Marco Marco - 1 year ago 89
MySQL Question

Laravel - query for column value in pivot table from relationship

I need to make an if statement for a query where I need to check if column

is set to
for players for that quiz in the pivot table
This is how to relationship is set up in the

public function players()
return $this->belongsToMany('App\Player', 'player_quiz')->withPivot('status');

I am not sure how to do that kind of query, to make it clearer here how it should basically look like:

if ($quiz->players()->where('status', 'rematch'))->get();

Answer Source

Try this one:

if ($quiz->players()->wherePivot('status', 'rematch')->get()) {
   // Do something
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download