I have a table registration_types that is associated with a conference, a conference can have multiple registration types.
So the registration_types table have columns like: id, name, price, conference_id.
And I want to do a query to check if for a specific conference there are registration types where the price is not free, that is the price is ">0".
I already have the conference id with:
$conference = Conference::where('id',$id)->firstOr(function(){
return redirect('/');
});
$conferenceID = $conference->id;
But now do you know how to know if there are registration types where the price is not 0 for that $conferenceID?
Models:
RegistrationType model:
class RegistrationType extends Model
{
public function conference(){
return $this->belongsTo('App\Conference');
}
}
Conference model:
class Conference extends Model
{
public function registrationTypes(){
return $this->hasMany('App\RegistrationType', 'conference_id');
}
}
Like this is not working
$paidConferencesExist = $conference->whereHas("registrationTypes", function($query){
$query->where('price', '>', '0');
});