I am using laravel 5.7
When I use whereHas
to check a relation’s existence, I face with Unknown column "has" in 'where clause
Error! Why?
this is my code:
JavaScript
x
$query->whereHas('departures', function ( $query) {
$query->whereBetween('depart_date', [date($this->data['departFrom_date']), date($this->data['departTo_date'])]);
});
and this is my model part:
JavaScript
public function departures()
{
return $this->hasMany(CruiseSailingDepartures::class);
}
Update:
The query was started with:
JavaScript
$query = DB::table('table_name');
Advertisement
Answer
I have found my problem, I was using DB::table('tablename')
instead of using the Model (TableName:: ...
)
Thanks for all answers